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

1 //授权控制器

2

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

你可能感兴趣的:(php拼多多登录下单接口)