无法登录
发布于 6 年前 作者 jie69 9497 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

无法获得openid

  • 预期表现

可以获得openid

  • 复现路径

每次都不行

  • 提供一个最简复现 Demo

wx.login({

success: ret => {

// 发送 res.code 到后台换取 openId, sessionKey, unionId

var $post = {

code: ret.code

}

console.log(“ret.code:” + ret.code)

console.log(“JSON_stringify:” + JSON.stringify($post))

wx.request({

url: https://aptcollege.cn/tp5/index.php/index/index/wx_req2,

data: { js_code: JSON.stringify($post) },

//data: { js_code: ret.code },

method: ‘POST’,

header: {

‘content-type’: ‘application/x-www-form-urlencoded’

},

success: function (res) {

wx.setStorageSync(‘third_session’, res.data);

console.log(res)

},

fail: function (err) {

console.log(err)

}

})

后台

public function wx_req2()

    {

header('Content-type:application/json');

$js_code = json_decode($_POST);

return json($js_code);

        $url='https://api.weixin.qq.com/sns/jscode2session?appid=wx565931e3e9fe2902&secret=beca69ba684c6db053c725c0719700f8&js_code='.$js_code.'&grant_type=authorization_code';

        //echo "url=[".$url."]</br>";

$wxRet = file_get_contents($url);  

        //echo $wxRet."</br>";

        $wxRet_Arr = json_decode($wxRet,true);


    }

1 回复

return json($js_code);

php先把code拿到了

回到顶部