'', 'client_id' => '', 'access_token' => '', // 非必填,通过code获取的access_token 'timestamp' => '', 'data_type' => '', // 非必填,响应格式,即返回数据的格式,JSON或者XML(二选一),默认JSON,注意是大写 'version' => '', // 非必填, API协议版本号,默认为V1,可不填 'sign' => '' ]; public function __construct() { } public function getAuthUrl($shopId, $platId) { $state = $shopId . '_' . $platId; return "https://oauth.pinduoduo.com/authorize/ktt?client_id={$this->clientId}&redirect_uri={$this->redirectUri}&state={$state}"; } public function auth() { $accessToken = $this->getAccessTokenWithCode(); $accessToken['pop_auth_token_create_response'] = json_encode($accessToken, 256); $this->shop->update($accessToken); return $this->shop; } public function getAccessTokenWithCode() { $type = 'pdd.pop.auth.token.create'; $res = $this->request($type, ['code' => $this->code]); return $res['pop_auth_token_create_response']; } public function getAccessToken() { return ''; } public function getSign($params) { $params = ksort($params); $str = ''; foreach ($params as $key => $val) { $str .= $key . $val; } $str = $this->clientSecret . $str . $this->clientSecret; return strtoupper(md5($str)); } public function request($type, $appendParams = [], $url = 'http://gw-api.pinduoduo.com/api/router') { $publicParams = [ 'type' => $type, 'client_id' => $this->clientId, 'timestamp' => time() ]; if ('pdd.pop.auth.token.create' !== $type) { $publicParams['access_token'] = $this->getAccessToken(); } $publicParams = array_merge($publicParams, $appendParams); $publicParams['sign'] = $this->getSign($publicParams); return $this->formDataPostRequest($url, $publicParams); } public function downloadGoodsAndBind($page = 1) { [$type, $appendParams] = Goods::downloadGoods($this->shop->owner_name, $page); $res = $this->formDataPostRequest($type, $appendParams); $goods = $res['ktt_goods_query_list_response']['goods_list']; Goods::bindGoods($goods, $this->shop->id); $pageNum = ceil($res['total'] / $appendParams['size']); if ($pageNum > $page && 10 >= $page) { $this->downloadGoodsAndBind($page + 1); } } public function incrQuantity($skuId) { $goodsSku = GoodsSku::query()->find($skuId); $business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id']); [$type, $appendParams] = Goods::incrQuantity($business->goodsId, $goodsSku->stock, $business->sku_id); $this->formDataPostRequest($type, $appendParams); $log = new Log(); $log->module = 'plat'; $log->action = 'POST'; $log->target_type = 'kuaituantuan'; $log->target_id = 0; $log->target_field = $type; $log->user_id = 1; $log->message = 'success'; $log->save(); } public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default') { if ('increment' === $downloadType) { [$type, $appendParams] = Order::downloadIncrementOrders($beginTime, $endTime, $activityNo); } else { [$type, $appendParams] = Order::downloadOrders($beginTime, $endTime, $activityNo); } $res = $this->formDataPostRequest($type, $appendParams); return $res['ktt_order_list_response']['order_list']; } public function bindGoods($goods) { // TODO: Implement bindGoods() method. } }