baseUrl = 'https://openic.sf-express.com/open/api/external/'; $this->devId = 1594082399; $this->appSecret = '9025c4f5ad93e8e08e947f02d0cde652'; } else { // $this->baseUrl = 'https://openic.sf-express.com/open/api/external/'; // $this->devId = 1741530942; // $this->appSecret = '07b3f83d19a4a9f89322976c936faf92'; $this->baseUrl = 'https://openic.sf-express.com/open/api/external/'; $this->devId = 1594082399; $this->appSecret = '9025c4f5ad93e8e08e947f02d0cde652'; } $this->shopId = $shopId; //保存 xhDeliveryAuthToken 表数据 $this->deliveryAuthToken = $deliveryAuthToken; //自定义设置取出与设置 $customSettingsStr = $deliveryAuthToken['customSettings']; $customSettings = json_decode($customSettingsStr, true); if(isset($customSettings['is_person_direct'])){ $this->isPersonDirect = $customSettings['is_person_direct']; } } /** * 获取店铺信息 * * 2025/2/17更新,返回参数更新,支持返回物流产品,详见logistic_type_list * 开发者可通过该接⼝获取到店铺的基础信息(非连锁店铺可以额外获得等级信息和补贴信息) * * @param string $shopId 店铺ID * @param int $shopType 店铺ID类型 1:顺丰店铺ID 2:接⼊⽅店铺ID * @return mixed */ public function getShopInfo($shopId=0, $shopType = 1) { if($shopId == 0){ $shopId = $this->shopId; } $params = [ 'shop_id' => $shopId, 'shop_type' => $shopType, 'push_time' => time() ]; $response = $this->httpRequest('getshopinfo', $params); // 检查API响应 if (isset($response['error_code']) && $response['error_code'] == 0) { // 更新自定义中的json数据 $delivery = DeliveryAuthTokenClass::getByCondition(['mainId'=>$this->deliveryAuthToken['mainId'], 'platform'=>'shunfeng'], true); $customSettingsJson = $delivery->customSettings; $customSettings = json_decode($customSettingsJson, true); $customSettings['is_person_direct'] = $response['result']['shop_info']['is_person_direct']; // 店铺是否支持专人直送,0不支持 1支持 2只能发独享专送 $customSettingsJson = json_encode($customSettings); $delivery->customSettings = $customSettingsJson; $delivery->save(); return [ 'success' => true, 'shop_info' => $response['result']['shop_info'] ?? [], 'message' => '获取店铺信息成功', ]; } return [ 'success' => false, 'shop_info' => [], 'message' => $response['error_msg'] ?? '获取店铺信息失败', ]; } public function getIsPersonDirect() { return $this->isPersonDirect; } /** * 构建API请求参数 * * 根据API规范构建完整的请求参数,包括签名 * * @param string $method API方法名 * @param array $businessData 业务参数 * @return array 完整的请求参数 */ protected function httpRequest($method, $businessData = []) { // 构建参数 $payload = [ 'dev_id' => $this->devId, 'shop_id' => $this->shopId, 'shop_type' => 1, //1:顺丰店铺ID 2:接入方店铺ID ]; $payload = array_merge($payload, $businessData); // 计算签名 $signature = $this->generateSignature($payload); $url = $this->baseUrl . $method . '?sign=' . $signature; $resp = HttpClient::post($url, $payload, [ 'Content-Type' => 'application/json', ]); return $resp; } public function generateSignature($params) { $post_data = json_encode($params); $sign_char = $post_data . "&{$this->devId}&{$this->appSecret}"; $sign = base64_encode(MD5($sign_char)); // 注:md5出来的结果是32位小写16进制字符串,$sign 的最终结果末尾包含等号= return $sign; } }