ajaxReturn([ 'status' => 0, 'msg' => 'code不能为空', ]); } $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->appId}&secret={$this->secert}&js_code={$code}"; $r = file_get_contents($url); $wxInfo = I('userInfo'); $wxUser =json_decode($r, true); $exist = M('mini_program_user', 'tab_')->where([ 'openid' => $wxUser['openid'] ])->find(); if (!$exist) { $wxInfoDeJson = json_decode($wxInfo, true); M('mini_program_user', 'tab_')->add([ 'openid' => $wxUser['openid'], 'unionid' => $wxUser['unionid'], 'wx_json' => $wxInfo, 'avatar' => $wxInfoDeJson['avatarUrl'], 'nickname' => $wxInfoDeJson['nickName'], 'city' => $wxInfoDeJson['city'], 'province' => $wxInfoDeJson['province'], 'country' => $wxInfoDeJson['country'], 'create_time' => time() ]); } echo $r; } }