|
@@ -41,9 +41,56 @@ class Kuaishou extends BaseUniPlatform
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- protected function createOrder($outOrderNo, $totalAmount): array
|
|
|
|
|
|
+ public function createOrder($outOrderNo, $totalAmount, $openId): array
|
|
{
|
|
{
|
|
- // TODO: Implement createOrder() method.
|
|
|
|
|
|
+ $data = [
|
|
|
|
+ 'app_id' => $this->appId,
|
|
|
|
+ 'out_order_no' => $outOrderNo,
|
|
|
|
+ 'open_id' => $openId,
|
|
|
|
+ 'total_amount' => intval($totalAmount * 100),
|
|
|
|
+ 'subject' => "订单号:".$outOrderNo,
|
|
|
|
+ 'detail' => '快手担保支付',
|
|
|
|
+ 'type' => 1233, // @url https://mp.kuaishou.com/docs/operate/platformAgreement/epayServiceCharge.html
|
|
|
|
+ 'expire_time' => $this->validTimestamp,
|
|
|
|
+ 'notify_url' => $this->noticeUrl
|
|
|
|
+ ];
|
|
|
|
+ $data['sign'] = $this->getSign($data);
|
|
|
|
+ $url = $this->API::CREATE_ORDER.'?'.http_build_query([
|
|
|
|
+ 'app_id' => $this->appId,
|
|
|
|
+ 'access_token' => $this->accessToken,
|
|
|
|
+ ]);
|
|
|
|
+ return $this->post(
|
|
|
|
+ $url,
|
|
|
|
+ $data,
|
|
|
|
+ 'json'
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param array $data
|
|
|
|
+ * @return string
|
|
|
|
+ */
|
|
|
|
+ public function getSign(array $data)
|
|
|
|
+ {
|
|
|
|
+ $filterArray = ['sign','access_token'];
|
|
|
|
+ $rList = array();
|
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
|
+ if (in_array($k, $filterArray))
|
|
|
|
+ continue;
|
|
|
|
+ $value = trim(strval($v));
|
|
|
|
+ $len = strlen($value);
|
|
|
|
+ if ($len > 1 && substr($value, 0, 1) == "\"" && substr($value, $len, $len - 1) == "\"")
|
|
|
|
+ $value = substr($value, 1, $len - 1);
|
|
|
|
+ $value = trim($value);
|
|
|
|
+ if ($value == "" || $value == "null")
|
|
|
|
+ continue;
|
|
|
|
+ array_push($rList, "$k=$value");
|
|
|
|
+ }
|
|
|
|
+ sort($rList, SORT_STRING);
|
|
|
|
+ $str = implode('&', $rList);
|
|
|
|
+ $str .= $this->secret;
|
|
|
|
+ return md5($str);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -76,21 +123,39 @@ class Kuaishou extends BaseUniPlatform
|
|
$this->accessTokenFile = storage_path('app/kuaishou/kuaishou_access_token.json');
|
|
$this->accessTokenFile = storage_path('app/kuaishou/kuaishou_access_token.json');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public function getNotifySign(array $data)
|
|
|
|
+ {
|
|
|
|
+ $str = json_encode($data,JSON_UNESCAPED_UNICODE).$this->secret;
|
|
|
|
+ return md5($str);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param string $uri
|
|
* @param string $uri
|
|
* @param array $data
|
|
* @param array $data
|
|
|
|
+ * @param string $type
|
|
* @return array
|
|
* @return array
|
|
* @throws \Exception
|
|
* @throws \Exception
|
|
*/
|
|
*/
|
|
- protected function post($uri = '', $data = []): array
|
|
|
|
|
|
+ protected function post($uri = '', $data = [], $type = 'urlencoded'): array
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
$client = new Client();
|
|
$client = new Client();
|
|
- $url = $uri.'?'.http_build_query($data);
|
|
|
|
- $res = $client->post($url, [
|
|
|
|
- 'verify' => false,
|
|
|
|
- 'headers' => ['Content-Type' => 'x-www-form-urlencoded'],
|
|
|
|
- ]);
|
|
|
|
|
|
+ if($type == 'urlencoded'){
|
|
|
|
+ $url = $uri.'?'.http_build_query($data);
|
|
|
|
+ $options = [
|
|
|
|
+ 'verify' => false,
|
|
|
|
+ 'headers' => ['Content-Type' => 'x-www-form-urlencoded'],
|
|
|
|
+ ];
|
|
|
|
+ }else{
|
|
|
|
+ $url = $uri;
|
|
|
|
+ $options = [
|
|
|
|
+ 'verify' => false,
|
|
|
|
+ 'headers' => ['Content-Type' => 'application/json'],
|
|
|
|
+ 'body' => json_encode($data)
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $res = $client->post($url, $options);
|
|
$stringBody = (string)$res->getBody();
|
|
$stringBody = (string)$res->getBody();
|
|
$res = json_decode($stringBody, true);
|
|
$res = json_decode($stringBody, true);
|
|
|
|
|
|
@@ -103,4 +168,10 @@ class Kuaishou extends BaseUniPlatform
|
|
throw new \Exception($e->getMessage());
|
|
throw new \Exception($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ protected function setNoticeUrl(): void
|
|
|
|
+ {
|
|
|
|
+ $this->noticeUrl = env('APP_URL').'/api/pay/kuaishou/notify';
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|