|
|
@@ -26,10 +26,34 @@ class IntraCityExpress
|
|
|
|
|
|
public static function getMerchant()
|
|
|
{
|
|
|
- $merchant = WxOpenClass::getMallWxInfo();
|
|
|
+ $merchant = WxOpenClass::getWxInfo();
|
|
|
return $merchant;
|
|
|
}
|
|
|
|
|
|
+ private static function generateSign($method, $url, $timestamp, $nonce, $body, $merchant)
|
|
|
+ {
|
|
|
+ $appId = $merchant['miniAppId'];
|
|
|
+ $serialNo = $merchant['serial_no'];
|
|
|
+ $privateKey = $merchant['private_key']; // Ensure this is the raw private key content
|
|
|
+
|
|
|
+ $parsedUrl = parse_url($url);
|
|
|
+ $path = $parsedUrl['path'] . (isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : '');
|
|
|
+
|
|
|
+ $message = "{$method}\n{$path}\n{$timestamp}\n{$nonce}\n{$body}\n";
|
|
|
+
|
|
|
+ openssl_sign($message, $signature, $privateKey, 'sha256WithRSAEncryption');
|
|
|
+ $base64Signature = base64_encode($signature);
|
|
|
+
|
|
|
+ return sprintf(
|
|
|
+ 'WECHATPAY2-SHA256-RSA2048 appid=%s,timestamp="%d",nonce_str="%s",signature="%s",serial_no="%s"',
|
|
|
+ $appId,
|
|
|
+ $timestamp,
|
|
|
+ $nonce,
|
|
|
+ $base64Signature,
|
|
|
+ $serialNo
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送HTTP请求
|
|
|
* @param string $url 请求URL
|
|
|
@@ -37,16 +61,58 @@ class IntraCityExpress
|
|
|
* @param string $accessToken access_token
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function sendRequest($url, $data, $accessToken)
|
|
|
+ public static function sendRequest($url, $data, $accessToken, $merchant = null)
|
|
|
+ {
|
|
|
+ if ($merchant === null) {
|
|
|
+ $merchant = self::getMerchant();
|
|
|
+ }
|
|
|
+
|
|
|
+ $curl = new curl\Curl();
|
|
|
+
|
|
|
+ // 添加access_token到URL
|
|
|
+ $urlWithToken = $url . (strpos($url, '?') !== false ? '&' : '?') . 'access_token=' . $accessToken;
|
|
|
+
|
|
|
+ $timestamp = time();
|
|
|
+ $nonce = \Yii::$app->security->generateRandomString();
|
|
|
+ $body = Json::encode($data);
|
|
|
+ if ($body === '[]') {
|
|
|
+ $body = '{}';
|
|
|
+ }
|
|
|
+
|
|
|
+ //$signature = self::generateSign('POST', $urlWithToken, $timestamp, $nonce, $body, $merchant);
|
|
|
+
|
|
|
+ $response = $curl->setOption(CURLOPT_POSTFIELDS, $body)
|
|
|
+ ->setOption(CURLOPT_HTTPHEADER, [
|
|
|
+ 'Content-Type: application/json',
|
|
|
+ 'Accept: application/json',
|
|
|
+ //'Authorization: ' . $signature
|
|
|
+ ])
|
|
|
+ ->post($urlWithToken);
|
|
|
+
|
|
|
+ // 确保响应是字符串格式再进行JSON解码
|
|
|
+ if (is_array($response)) {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Json::decode($response, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function emptyRequest($url, $accessToken)
|
|
|
{
|
|
|
$curl = new curl\Curl();
|
|
|
|
|
|
// 添加access_token到URL
|
|
|
$urlWithToken = $url . (strpos($url, '?') !== false ? '&' : '?') . 'access_token=' . $accessToken;
|
|
|
|
|
|
- $response = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))
|
|
|
- ->post($urlWithToken);//->setOption(CURLOPT_HTTPHEADER, ['Content-Type: application/json'])
|
|
|
+ $response = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode(new \stdClass()))
|
|
|
+ ->setOption(CURLOPT_HTTPHEADER, ['Content-Type: application/json'])
|
|
|
+ ->post($urlWithToken);
|
|
|
|
|
|
+ // 确保响应是字符串格式再进行JSON解码
|
|
|
+ if (is_array($response)) {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
return Json::decode($response, true);
|
|
|
}
|
|
|
|
|
|
@@ -58,6 +124,9 @@ class IntraCityExpress
|
|
|
const API_UPDATE_STORE = self::API_BASE_URL . '/updatestore';
|
|
|
const API_QUERY_STORE = self::API_BASE_URL . '/querystore';
|
|
|
|
|
|
+ // 开通门店权限
|
|
|
+ const API_APPLY_STORE = self::API_BASE_URL . '/apply';
|
|
|
+
|
|
|
// 订单管理
|
|
|
const API_ADD_ORDER = self::API_BASE_URL . '/addorder';
|
|
|
const API_CANCEL_ORDER = self::API_BASE_URL . '/cancelorder';
|
|
|
@@ -90,6 +159,14 @@ class IntraCityExpress
|
|
|
$merchant = self::getMerchant();
|
|
|
}
|
|
|
|
|
|
+// $re = self::applyStore($merchant, $ptStyle);
|
|
|
+// if (!is_array($re)) {
|
|
|
+// $re = Json::decode($re, true);
|
|
|
+// }
|
|
|
+// if ($re['errcode'] != 0) {
|
|
|
+// return $re;
|
|
|
+// }
|
|
|
+
|
|
|
$accessToken = self::getAccessToken($merchant, $ptStyle);
|
|
|
|
|
|
$data = [
|
|
|
@@ -102,7 +179,7 @@ class IntraCityExpress
|
|
|
'service_type' => $storeData['service_type'] ?? 1, // 默认同城配送
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest(self::API_CREATE_STORE, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_CREATE_STORE, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -128,7 +205,7 @@ class IntraCityExpress
|
|
|
'store_phone' => $storeData['store_phone'] ?? null,
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest(self::API_UPDATE_STORE, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_UPDATE_STORE, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -150,7 +227,25 @@ class IntraCityExpress
|
|
|
'out_store_id' => $outStoreId,
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest(self::API_QUERY_STORE, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_QUERY_STORE, $data, $accessToken, $merchant);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开通门店权限
|
|
|
+ * @param null $merchant
|
|
|
+ * @param int $ptStyle
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function applyStore($merchant = null, $ptStyle = 0)
|
|
|
+ {
|
|
|
+ if ($merchant === null) {
|
|
|
+ $merchant = self::getMerchant();
|
|
|
+ }
|
|
|
+
|
|
|
+ $accessToken = self::getAccessToken($merchant, $ptStyle);
|
|
|
+
|
|
|
+ return self::sendRequest(self::API_APPLY_STORE, new \stdClass(), $accessToken, $merchant);
|
|
|
+ //return self::getRequest(self::API_APPLY_STORE, $accessToken);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -203,7 +298,7 @@ class IntraCityExpress
|
|
|
'sub_biz_id' => $orderData['sub_biz_id'] ?? '',
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest(self::API_ADD_ORDER, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_ADD_ORDER, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -255,7 +350,7 @@ class IntraCityExpress
|
|
|
'sub_biz_id' => $orderData['sub_biz_id'] ?? '',
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest(self::API_PRE_ADD_ORDER, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_PRE_ADD_ORDER, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -286,7 +381,7 @@ class IntraCityExpress
|
|
|
$data['out_store_id'] = $outStoreId;
|
|
|
}
|
|
|
|
|
|
- return self::sendRequest(self::API_CANCEL_ORDER, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_CANCEL_ORDER, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -317,7 +412,7 @@ class IntraCityExpress
|
|
|
$data['out_store_id'] = $outStoreId;
|
|
|
}
|
|
|
|
|
|
- return self::sendRequest(self::API_GET_ORDER, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_GET_ORDER, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -342,7 +437,7 @@ class IntraCityExpress
|
|
|
'limit' => $limit,
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest($url, $data, $accessToken);
|
|
|
+ return self::sendRequest($url, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
// ==================== 运力管理接口 ====================
|
|
|
@@ -361,7 +456,7 @@ class IntraCityExpress
|
|
|
$accessToken = self::getAccessToken($merchant, $ptStyle);
|
|
|
$url = 'https://api.weixin.qq.com/cgi-bin/express/intracity/delivery/list';
|
|
|
|
|
|
- return self::sendRequest($url, [], $accessToken);
|
|
|
+ return self::sendRequest($url, new \stdClass(), $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -384,7 +479,7 @@ class IntraCityExpress
|
|
|
'delivery_id' => $deliveryId,
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest($url, $data, $accessToken);
|
|
|
+ return self::sendRequest($url, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
// ==================== 资金管理接口 ====================
|
|
|
@@ -404,7 +499,7 @@ class IntraCityExpress
|
|
|
$accessToken = self::getAccessToken($merchant, $ptStyle);
|
|
|
$data = ['out_store_id' => $outStoreId];
|
|
|
|
|
|
- return self::sendRequest(self::API_GET_BALANCE, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_GET_BALANCE, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -429,7 +524,7 @@ class IntraCityExpress
|
|
|
'amount' => $amount,
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest(self::API_CHARGE_STORE, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_CHARGE_STORE, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -454,7 +549,7 @@ class IntraCityExpress
|
|
|
'out_charge_id' => $outChargeId,
|
|
|
];
|
|
|
|
|
|
- return self::sendRequest(self::API_REFUND_STORE, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_REFUND_STORE, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -473,7 +568,7 @@ class IntraCityExpress
|
|
|
$accessToken = self::getAccessToken($merchant, $ptStyle);
|
|
|
$data = ['out_charge_id' => $outChargeId];
|
|
|
|
|
|
- return self::sendRequest(self::API_GET_CHARGE_RECORD, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_GET_CHARGE_RECORD, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
// ==================== 测试接口 ====================
|
|
|
@@ -508,7 +603,7 @@ class IntraCityExpress
|
|
|
$data['store_order_id'] = $outOrderId;
|
|
|
}
|
|
|
|
|
|
- return self::sendRequest(self::API_MOCK_NOTIFY, $data, $accessToken);
|
|
|
+ return self::sendRequest(self::API_MOCK_NOTIFY, $data, $accessToken, $merchant);
|
|
|
}
|
|
|
|
|
|
/**
|