getcode(){
let that = this
uni.login({
success:function(res){
let code = res.code
that.getopenid(code)
}
})
},
getopenid(code){
console.log(code,"传递的code")
this.$axios.axios(
'POST',
this.$paths.indexGetOpid, {
code:code
}
).then(res => {
if (res.code == 1) {
console.log(res.data)
this.openid = res.data.openid
}
console.log(res, "openid获取")
})
},
public function getOpid()
{
$appid = 'xxx';
$secret = 'xxx';
$code = Request()->param('code');
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid . '&secret='.$secret.'&js_code='.$code.'&grant_type=authorization_code';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 5000);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
$data = json_decode($res,true);
$this->success('成功',$data);
}