盲盒购物网站系统开发建设 第三篇

前面更新了两篇,这个是第三篇,也就是盲盒购物网站系统开发建设 第三篇,直接更新代码就可以了。

在公网接口处重写此方法:验证服务器有效性

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));
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞鸿腾达的技术猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值