加入收藏 | 设为首页 | 会员中心 | 我要投稿 四平站长网 (https://www.0434zz.com.cn/)- 云服务器、对象存储、基础存储、视频终端、数据应用!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP实现支付宝登录

发布时间:2022-08-02 14:25:18 所属栏目:PHP教程 来源:互联网
导读:1.支付宝路由拼接 public function dev() { $http = https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm?; $app_id = ; $scope = auth_user; $redirect_uri = urlencode(); $state = 0; $url = $http . app_id= . $app_id . scope= . $scope . r
   1.支付宝路由拼接
      public function dev()
      {
          $http = 'https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm?';
          $app_id = '';
          $scope = 'auth_user';
          $redirect_uri = urlencode('');
          $state = '0';
          $url = $http . 'app_id=' . $app_id . '&scope=' . $scope . '&redirect_uri=' . $redirect_uri . '&state=' . $state;
          $this->redirect($url);
      }
  复制代码
  2.支付宝的回调页面
 
  复制代码
  public function zhi()
      {
          $params = input();
          require_once './plugins/auth/AopSdk.php';
          $aop = new AopClient ();
          $aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
          $aop->appId = '2016100200645172';
          $aop->rsaPrivateKey = '私钥';
          $aop->alipayrsaPublicKey = '公钥';
          $aop->apiVersion = '1.0';
          $aop->signType = 'RSA2';
          $aop->postCharset = 'UTF-8';
          $aop->format = 'json';
          $request = new AlipaySystemOauthTokenRequest ();
          $request->setGrantType("authorization_code");
          $request->setCode($params['auth_code']);
          $result = $aop->execute($request);
          $result = (new thinkCollection($result))->toArray();
          $access_token = $result['alipay_system_oauth_token_response']->access_token ?? '';
          if (!$access_token) {
              echo json_encode(['msg' => 'code无效'], JSON_UNESCAPED_UNICODE);
          }
          $request = new AlipayUserInfoShareRequest ();
          $result = $aop->execute($request, $access_token);
          apphomelogicAuto::ali($result);
          $list = appcommonmodelUser::where('open_type', 'alipay')->where('openid', $result->alipay_user_info_share_response->user_id)->find();
          session('user_info', $list->toArray());
          $blank_url = session('blank_url') ?: 'home/index/index';
          apphomelogicCartLogic::cookieToDb();
          $this->redirect($blank_url);
      }

(编辑:四平站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读