登录接口
public function wxlogin(Request $request){
//获取code
$code = $request->post('code');
//微信公众平台获取AppId
$appid = '***';
//从微信公众平台获取AppSecret
$appSecret = '***';
//微信开发文档->服务端->小程序登录获取
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$appid.'&secret='.$appSecret.'&js_code='.$code.'&grant_type=authorization_code';
//放入字符串后转换为数组
$url = json_decode(file_get_contents($url),true);
//查找是否登录过
$user = Login::where('openid',$url['openid'])->first();
if (!$user) {
//没登录在数据库内添加用户
Login::create($url);
return response(['code' => 200, 'data' => '', 'msg' => '登录成功']);
}else{
//登录了