Skip to content

Commit

Permalink
alipay url 中增加 charset 避免编码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yansongda committed Jul 13, 2019
1 parent e95807c commit 116b217
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/Gateways/Alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class Alipay implements GatewayApplicationInterface
* Const url.
*/
const URL = [
self::MODE_NORMAL => 'https://openapi.alipay.com/gateway.do',
self::MODE_DEV => 'https://openapi.alipaydev.com/gateway.do',
self::MODE_NORMAL => 'https://openapi.alipay.com/gateway.do?charset=utf-8',
self::MODE_DEV => 'https://openapi.alipaydev.com/gateway.do?charset=utf-8',
];

/**
Expand Down Expand Up @@ -153,7 +153,6 @@ public function verify($data = null, $refund = false): Collection
$request = Request::createFromGlobals();

$data = $request->request->count() > 0 ? $request->request->all() : $request->query->all();
$data = Support::encoding($data, 'utf-8', $data['charset'] ?? 'gb2312');
}

if (isset($data['fund_bill_list'])) {
Expand Down
9 changes: 2 additions & 7 deletions src/Gateways/Alipay/Support.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ public static function requestApi(array $data): Collection
return ($value == '' || is_null($value)) ? false : true;
});

$result = mb_convert_encoding(self::$instance->post('', $data), 'utf-8', 'gb2312');

$result = json_decode($result, true);
$result = json_decode(self::$instance->post('', $data), true);

Events::dispatch(new Events\ApiRequested('Alipay', '', self::$instance->getBaseUri(), $result));

Expand Down Expand Up @@ -209,8 +207,7 @@ public static function verifySign(array $data, $sync = false, $sign = null): boo

$sign = $sign ?? $data['sign'];

$toVerify = $sync ? mb_convert_encoding(json_encode($data, JSON_UNESCAPED_UNICODE), 'gb2312', 'utf-8') :
self::getSignContent($data, true);
$toVerify = $sync ? json_encode($data, JSON_UNESCAPED_UNICODE) : self::getSignContent($data, true);

$isVerify = openssl_verify($toVerify, base64_decode($sign), $publicKey, OPENSSL_ALGO_SHA256) === 1;

Expand All @@ -233,8 +230,6 @@ public static function verifySign(array $data, $sync = false, $sign = null): boo
*/
public static function getSignContent(array $data, $verify = false): string
{
$data = self::encoding($data, $data['charset'] ?? 'gb2312', 'utf-8');

ksort($data);

$stringToBeSigned = '';
Expand Down

2 comments on commit 116b217

@yansongda
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix #247 , #249

@yansongda
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe fix #254

Please sign in to comment.