| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace app\extra\tools;
- class ZtExpress
- {
- /**
- * 接口地址
- * @var string
- */
- protected string $gateway = "https://japi-test.zto.com";
- protected array $config = [];
- /**
- * 设置配置权限
- * @param array $data
- * @return $this
- */
- public function config(array $data = [])
- {
- $this->config = $data;
- if ($data['version'] == "test")
- {
- $this->gateway = "https://japi-test.zto.com";
- } else {
- $this->gateway = "https://japi.zto.com";
- }
- return $this;
- }
- /**
- * 下单
- * @param array $sendData 发货信息
- * @param array $endData 收件人信息
- * @return array
- */
- public function createOrder(array $sendData = [],array $endData = [],string $orderId = "",int $expressType = 1): array
- {
- $param = [
- "partnerType" => 2,
- "orderType" => 1,
- "partnerOrderCode" => $orderId,
- "senderInfo" => [
- "senderName" => $endData['username'],
- "senderMobile" => $endData['mobile'],
- "senderProvince" => "",
- "senderCity" => "",
- "senderDistrict" => "",
- "senderAddress" => "",
- ]
- ];
- if ($this->config['version'] == "test")
- {
- $param['accountInfo']['accountPassword'] = $this->config['account'];
- } else {
- $param['accountInfo']['accountId'] = $this->config['account'];
- }
- }
- /**
- * 获取签名
- * @param array $params
- * @return string
- */
- protected function getSign(array $params = []): string
- {
- $fixedParams = array();
- foreach ($params as $k => $v) {
- if (gettype($v) != "string") {
- $fixedParams += [$k => json_encode($v)];
- } else {
- $fixedParams += [$k => $v];
- }
- }
- $str_to_digest = "";
- foreach ($fixedParams as $k => $v) {
- $str_to_digest = $str_to_digest .$k ."=" .$v ."&";
- }
- $str_to_digest = substr($str_to_digest, 0, -1) .$this->config['secret'];
- return base64_encode(md5($str_to_digest, true));
- }
- }
|