openid 转化 token
onLoad: function (options) {
wx.login({
success:res=>{
//提交
wx.request({
url: 'http://www.longmai.com/API/code_select',
data:{
code:res.code,
},
success:function(success){
wx.setStorageSync('token',success.data.token)
}
})
}
})
},
controller
public function codeSelect()
{
$code = input('code');
$url = sprintf(config('wx.wxLoginUrl'), config('wx.AppID'), config('wx.AppSecret'), $code);
//获取openid
$data = curlGet($url);
//进行查询数据库里面是否有该用户,如果没有,则进行新增
$user = login::where('openid', $data['openid'])->find();
if (empty($user)){
$user = login::create([
'openid'=>$data[&