From a3fcf130ae77cd8c5f33195c4ea868c21b07f835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=93=AD=E9=98=B3?= Date: Sat, 22 Apr 2017 14:20:57 +0800 Subject: [PATCH] Fix payment tools API (#660) * Fix. * Fix. --- src/Payment/API.php | 9 +++++---- tests/Payment/PaymentAPITest.php | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Payment/API.php b/src/Payment/API.php index 415df0a4b..7b877e5be 100644 --- a/src/Payment/API.php +++ b/src/Payment/API.php @@ -57,8 +57,9 @@ class API extends AbstractAPI const API_QUERY_REFUND = '/pay/refundquery'; const API_DOWNLOAD_BILL = '/pay/downloadbill'; const API_REPORT = '/payitil/report'; - const API_URL_SHORTEN = '/tools/shorturl'; - const API_AUTH_CODE_TO_OPENID = '/tools/authcodetoopenid'; + + const API_URL_SHORTEN = 'https://api.mch.weixin.qq.com/tools/shorturl'; + const API_AUTH_CODE_TO_OPENID = 'https://api.mch.weixin.qq.com/tools/authcodetoopenid'; // order id types. const TRANSACTION_ID = 'transaction_id'; @@ -321,7 +322,7 @@ public function downloadBill($date, $type = self::BILL_TYPE_ALL) */ public function urlShorten($url) { - return $this->request($this->wrapApi(self::API_URL_SHORTEN), ['long_url' => $url]); + return $this->request(self::API_URL_SHORTEN, ['long_url' => $url]); } /** @@ -359,7 +360,7 @@ public function report($api, $timeConsuming, $resultCode, $returnCode, array $ot */ public function authCodeToOpenId($authCode) { - return $this->request($this->wrapApi(self::API_AUTH_CODE_TO_OPENID), ['auth_code' => $authCode]); + return $this->request(self::API_AUTH_CODE_TO_OPENID, ['auth_code' => $authCode]); } /** diff --git a/tests/Payment/PaymentAPITest.php b/tests/Payment/PaymentAPITest.php index d99560ec8..41e5776b3 100755 --- a/tests/Payment/PaymentAPITest.php +++ b/tests/Payment/PaymentAPITest.php @@ -26,7 +26,7 @@ class PaymentAPITest extends TestCase * * @return API */ - public function getAPI() + public function getAPI($sandboxEnabled = false) { $http = \Mockery::mock(Http::class); @@ -51,7 +51,7 @@ public function getAPI() $api->shouldReceive('wrapApi')->passthru(); $api->shouldReceive('getHttp')->andReturn($http); - return $api; + return $api->sandboxMode($sandboxEnabled); } /** @@ -229,10 +229,15 @@ public function testDownloadBill() public function testUrlShorten() { $api = $this->getAPI(); - $response = $api->urlShorten('http://easywechat.org'); - $this->assertEquals($api->wrapApi(API::API_URL_SHORTEN), $response['api']); + $this->assertEquals('https://api.mch.weixin.qq.com/tools/shorturl', $response['api']); + $this->assertEquals('http://easywechat.org', $response['params']['long_url']); + + $sandboxPayment = $this->getAPI(true); + $response = $sandboxPayment->urlShorten('http://easywechat.org'); + + $this->assertEquals('https://api.mch.weixin.qq.com/tools/shorturl', $response['api']); $this->assertEquals('http://easywechat.org', $response['params']['long_url']); } @@ -245,7 +250,13 @@ public function testAuthCodeToOpenId() $response = $api->authCodeToOpenId('authcode'); - $this->assertEquals($api->wrapApi(API::API_AUTH_CODE_TO_OPENID), $response['api']); + $this->assertEquals('https://api.mch.weixin.qq.com/tools/authcodetoopenid', $response['api']); + $this->assertEquals('authcode', $response['params']['auth_code']); + + $sandboxPayment = $this->getAPI(true); + $response = $sandboxPayment->authCodeToOpenId('authcode'); + + $this->assertEquals('https://api.mch.weixin.qq.com/tools/authcodetoopenid', $response['api']); $this->assertEquals('authcode', $response['params']['auth_code']); }