收藏
回答

openid 怎么获取

问题模块
API和组件

api.weixin.qq.com 现在不能加白名单,那么 openid 怎么获取




加急+++

最后一次编辑于  2017-08-02  (未经腾讯允许,不得转载)
回答关注问题邀请回答
收藏

1 个回答

  • 麦琪
    麦琪
    2017-08-02

    JS部分

    wx.login({
        success:function(code){
            wx.request({
              url:'test.php',
              data:{
                code:code
              },
              method:'POST',
              header:{'content-type':'application/x-www-form-urlencoded;charset=UTF-8'},
              success: function(res){
                console.log(res)
              }
            })
        }
    })



    PHP部分(我只会PHP,要是其它语言的,你自己看着改吧)

    $code = $_POST['code'];
    $url = 'https://api.weixin.qq.com/sns/jscode2session?appid=your_appid&secret=your_secret&grant_type=authorization_code&js_code='.$code;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $data = curl_exec($curl);
    curl_close($curl);
    $data = explode("{",$data);
    $data = explode("}",$data[1]);
    echo '{'.$data[0].'}';


    2017-08-02
    赞同
    回复