盲盒购物网站系统开发建设 第三篇
哄哄 -
前面更新了两篇,这个是第三篇,也就是盲盒购物网站系统开发建设 第三篇,直接更新代码就可以了。
在公网接口处重写此方法:验证服务器有效性
public function serverValidation()
{
$TOKEN = 'I8cezsHeF1buiCBPwD';
$signature = $_GET["signature"] ?? "";
$timestamp = $_GET["timestamp"] ?? "";
$nonce = $_GET["nonce"] ?? "";
$tmpArr = array($TOKEN, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
if ($tmpStr == $signature) {
return $_GET["echostr"] ?? '';
}
return 'error';
}
获取用户信息
if ('snsapi_userinfo' == $res['scope']) {
$userinfo = file_get_contents("https://api.weixin.qq.com/sns/userinfo?access_token={$res['access_token']}&openid={$res['openid']}&lang=zh_CN");
$userinfo = json_decode($userinfo, true);
if (!empty($userinfo['errcode']) && !empty($userinfo['errmsg'])) {
$redirect = $redirect . (strpos($redirect, '?') ? '&' : '?') . 'status=0&token=&errmsg=' . $userinfo['errmsg'];
$this->redirect($redirect ? urldecode($redirect) : '/h5/#/');
exit();
}
绑定过手机,直接去首页
if ($this->has_mobile) {
$this->redirect('/h5/#/?status=1&errmsg=&token=' . $token . "&is_notice=". $this->is_notice);
}
$redirect = $redirect . (strpos($redirect, '?') ? '&' : '?') . 'status=1&errmsg=&token=' . $token . "&is_notice=". $this->is_notice;
$this->redirect($redirect ? urldecode($redirect) : '/h5/#/');
}
$errmsg = $this->_error ?: '授权失败';
$redirect = $redirect . (strpos($redirect, '?') ? '&' : '?') . 'status=0&token=&errmsg=' . $errmsg;
$this->redirect($redirect ? urldecode($redirect) : '/h5/#/');
}
登录
private function login($openid, $nickname = '', $avatar = '', $invite_code = '', $is_channel ='')
{
$user = \app\common\model\User::getByWechatOpenid($openid);
if ($user) {
if ($user->status != 'normal') {
$this->_error = '账号被锁定';
return false;
}
//如果已经有账号则直接登录
$ret = $this->auth->direct($user->id);
} else {
$extend = [
'invite_code' => $invite_code,
'wechat_openid' => $openid,
'nickname' => $nickname,
'avatar' => $avatar,
];
$ret = $this->auth->register('', Random::alnum(), '', '', $extend);
if($ret && $is_channel == '49ba59abbe56e057'){ //赠送10金币
\app\common\model\User::where(['id'=>$this->auth->id])->setInc("coin", 10);
$this->is_notice = 1;
}
}
if ($ret) {
$data = $this->auth->getUserinfo();
$this->has_mobile = !empty($data['mobile']) ? true : false;
return $data['token'];
}
$this->_error = $this->auth->getError();
return false;
}
微信登录并重定向
public function wechatLoginRedirect()
{
$redirect = input('redirect');
if (empty('')) {
throw new HttpResponseException(Response::create(['code' => 403, 'msg' => '重定向地址为空', 'data' => null], 'json', 200));
}
$this->redirect('/index/wechat/bootToUrl?url=' . base64_encode($redirect));
}
}
特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。
php介绍
PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。
上一篇: 电商小程序开发的关键在哪里?
下一篇: 商城小程序开发小程序软件开发