php拼多多登录下单接口,对接拼多多授权登录及店铺信息接口_tp5

1 //授权控制器

2 <?php3 namespace app\index\controller;4 usethink\Controller;5 usethink\Db;6 usethink\Request;7 usethink\Session;8 class Index extendsController9 {10 private $clientId = "fea8cf1cfc75421e929115902f5a60cb";11 private $clientSecret = "286933c544380ac846be5f2938b7f276dee85132";12 private $accessToken;13 /**14 * 进入授权页面15 */

16 public functionindex(){17 return $this->fetch('Index/loginin');18 }19

20 /**21 * 授权接口22 * @throws \think\Exception23 * @throws \think\db\exception\DataNotFoundException24 * @throws \think\db\exception\ModelNotFoundException25 * @throws \think\exception\DbException26 * @throws \think\exception\PDOException27 */

28 public function login(Request $request)29 {30 $state = $request->param('state');31 //初始化数据库

32 $db = Db::connect('pfpartner');33

34 $data["code"] = $_GET["code"];35 $data["grant_type"] = "authorization_code";36 $data["client_id"] = $this->clientId;37 $data["client_secret"] = $this->clientSecret;38

39 $arr_header[] = "Content-Type:application/json";40 $resJson = http_request_post("http://open-api.pinduoduo.com/oauth/token",json_encode($data),true,$arr_header);41

42 $resArr = json_decode($resJson,true);43

44 $this->accessToken = $resArr['access_token'];45 $scope = json_encode($resArr['scope']);46

47

48 //判断该店铺是否授权过

49 $user = $db->name("open_user")->where('owner_id','=',$resArr['owner_id'])->find();50

51 //获取店铺信息

52 $shopJson = $this->getShopInfo();53 $shopInfo = json_decode($shopJson,true);54 if (empty($shopInfo["mall_info_get_response"])){55 return $this->redirect('http://pdd.shanyanzhineng.com');56 }57 /***店铺信息S*************************************/

58 $userInfo['logo'] = $shopInfo["mall_info_get_response"]['logo'];59 $userInfo['mall_name'] = $shopInfo["mall_info_get_response"]['mall_name'];60 $userInfo['mall_desc'] = $shopInfo["mall_info_get_response"]['mall_desc'];61 /***店铺信息E*************************************/

62

63 //var_dump($shopInfo);die;

64

65 $userInfo['owner_id'] = $resArr['owner_id'];66 $userInfo['owner_name'] = $resArr['owner_name'];67 $userInfo['login_num'] = $user['login_num']+1;68 $userInfo['login_time'] = date('Y-m-d H:i:s');69 $userInfo['access_token'] = $resArr['access_token'];70 $userInfo['expires_in'] = $resArr['expires_in'];71 $userInfo['refresh_token'] = $resArr['refresh_token'];72 $userInfo['scope'] = $scope;73 $userInfo['is_token'] = '0';74 $userInfo['is_cookie'] = '0';75

76 /***记录登录日志S*************************************/

77 $loginLog['owner_id'] = $resArr['owner_id'];78 $loginLog['mall_name'] = $shopInfo["mall_info_get_response"]['mall_name'];79 $loginLog['open_info'] = $resJson;80 $db->name("login_log")->insert($loginLog

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值