• 请不要在回答技术问题时复制粘贴 AI 生成的内容
vfx666
V2EX  ›  程序员

个人微信公众号做网页端开发时如何获取用户 openid?

  •  
  •   vfx666 · Dec 22, 2023 · 2161 views
    This topic created in 1060 days ago, the information mentioned may be changed or developed.

    貌似只有服务号才有这个接口。 主要想实现根据用户微信来自动登录的功能

    6 replies  •  2023-12-23 16:19:50 +08:00
    08110920
    08110920
    Dec 22, 2023
    1
    个人没有这个接口,不过 如果你想实现微信登录的话 可以试试下面这个方法
    <?php
    //假设你的页面地址为:http://pay.vwzx.com/wxjspay.php?trade_no=2023021920193467277
    //那么你可以这样访问:https://www.iunpay.com/wechat/third_user?target=urlencode( http://pay.vwzx.com/wxjspay.php?trade_no=2023021920193467277)
    //默认为静默授权,如果你想得到完整信息,则后面可以跟另一个参数 &wechat_scope=snsapi_userinfo(或者 snsapi_base)
    //询问授权(openid 、昵称、头像、unionid):snsapi_userinfo 静默授权(openid):snsapi_base

    if(!isset($_GET ['openid'])){
    $user_reg = "https://www.ikam.cn/user_reg.php";//注册地址,该地址必须接收 get 参数哦
    $url = "https://www.iunpay.com/wechat/third_user?target=".urlencode($user_reg);
    //触发微信 oauth 返回 openid
    Header("Location: $url");
    exit();
    }else{
    $openid = $_GET ['openid'];
    //这里你可以自动实现注册逻辑咯。
    }
    sarices
    sarices
    Dec 22, 2023
    2
    可以试试自定义菜单触发消息推送,让客户点击消息链接实现自动登录
    vfx666
    vfx666
    OP
    Dec 22, 2023 via iPhone
    3
    @08110920 这个 iunpay 是啥?第三方接口么
    stobacco
    stobacco
    Dec 23, 2023
    4
    @08110920 这是啥原理
    vfx666
    vfx666
    OP
    Dec 23, 2023 via iPhone
    6
    @horsebean 这个需要是服务号才行,个人的不行啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2411 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 12:29 · PVG 20:29 · LAX 04:29 · JFK 07:29
    ♥ Do have faith in what you're doing.