├── LICENSE ├── README.md ├── composer.json └── src ├── Alipay ├── Params │ ├── Pay │ │ ├── BusinessParams.php │ │ └── Request.php │ ├── PublicParams.php │ ├── Refund │ │ ├── BusinessParams.php │ │ └── Request.php │ ├── RefundPwd │ │ ├── BusinessParams.php │ │ └── Request.php │ └── WapPay │ │ ├── BusinessParams.php │ │ ├── ExtUserInfo.php │ │ └── Request.php └── SDK.php ├── AlipayApp ├── Agreement │ └── Params │ │ ├── Modify │ │ ├── BusinessParams.php │ │ └── Request.php │ │ ├── Query │ │ ├── BusinessParams.php │ │ └── Request.php │ │ ├── Sign │ │ ├── BusinessParams.php │ │ └── Request.php │ │ └── UnSign │ │ ├── BusinessParams.php │ │ └── Request.php ├── App │ ├── ExtUserInfo.php │ └── Params │ │ └── Pay │ │ ├── BusinessParams.php │ │ ├── ExtendParams.php │ │ └── Request.php ├── FTF │ └── Params │ │ ├── ExtendParams.php │ │ ├── GoodsDetail.php │ │ ├── Pay │ │ ├── BusinessParams.php │ │ └── Request.php │ │ └── QR │ │ ├── BusinessParams.php │ │ └── Request.php ├── Fund │ ├── Query │ │ ├── BusinessParams.php │ │ └── Request.php │ ├── Transfer │ │ ├── BusinessParams.php │ │ └── Request.php │ └── UniTransfer │ │ ├── BusinessParams.php │ │ ├── PayeeInfoParams.php │ │ └── Request.php ├── MiniApp │ └── Params │ │ └── Pay │ │ ├── BusinessParams.php │ │ ├── ExtendParams.php │ │ └── Request.php ├── Page │ └── Params │ │ ├── GoodsDetail.php │ │ └── Pay │ │ ├── BusinessParams.php │ │ ├── ExtendParams.php │ │ └── Request.php ├── Params │ ├── Cancel │ │ ├── BusinessParams.php │ │ └── Request.php │ ├── Close │ │ ├── BusinessParams.php │ │ └── Request.php │ ├── DownloadBill │ │ ├── BusinessParams.php │ │ └── Request.php │ ├── PublicParams.php │ ├── Query │ │ ├── BusinessParams.php │ │ └── Request.php │ ├── Refund │ │ ├── BusinessParams.php │ │ └── Request.php │ ├── RefundQuery │ │ ├── BusinessParams.php │ │ └── Request.php │ └── Settle │ │ ├── BusinessParams.php │ │ ├── Request.php │ │ └── RoyaltyParameter.php ├── SDK.php └── Wap │ └── Params │ └── Pay │ ├── BusinessParams.php │ ├── ExtendParams.php │ └── Request.php ├── AlipayCrossBorder ├── Customs │ ├── Query │ │ └── Request.php │ └── Submit │ │ └── Request.php ├── InStore │ ├── BarcodePay │ │ ├── ExtendInfo.php │ │ └── Request.php │ ├── Cancel │ │ └── Request.php │ ├── CreateMerchantQR │ │ ├── BizData.php │ │ ├── ChannelFee.php │ │ └── Request.php │ ├── CreateQR │ │ └── Request.php │ ├── ModifyMerchantQR │ │ └── Request.php │ ├── ModifyStatus │ │ └── Request.php │ ├── PreCreate │ │ ├── ExtendInfo.php │ │ ├── GoodsDetail.php │ │ └── Request.php │ ├── Query │ │ └── Request.php │ └── Refund │ │ └── Request.php ├── Online │ ├── DownloadCompare │ │ └── Request.php │ ├── DownloadSettlement │ │ └── Request.php │ ├── ExchageRate │ │ └── Request.php │ ├── Notify │ │ ├── Base.php │ │ ├── Pay.php │ │ └── Sync.php │ ├── NotifyVerify │ │ └── Request.php │ ├── Pay │ │ └── Request.php │ ├── Query │ │ └── Request.php │ ├── Refund │ │ └── Request.php │ └── WapPay │ │ └── Request.php ├── Params │ ├── PublicParams.php │ └── SplitFundInfo.php └── SDK.php ├── AlipayRequestBase.php ├── Base.php ├── Lib ├── CertUtil.php ├── Encrypt │ ├── AES.php │ ├── AES256GCM.php │ ├── Base.php │ ├── DSA.php │ ├── RSA.php │ ├── RSA2.php │ └── SHA256withRSA │ │ ├── SignatureResult.php │ │ └── Signer.php ├── ObjectToArray.php ├── Util.php └── XML.php ├── NotifyBase.php ├── PublicBase.php ├── RequestBase.php ├── Traits ├── FormParams.php ├── JSONParams.php └── XMLParams.php ├── Weixin ├── APP │ └── Params │ │ ├── Client │ │ └── Request.php │ │ ├── Pay │ │ └── Request.php │ │ └── SceneInfo.php ├── AuthCodeToOpenid │ └── Request.php ├── CloseOrder │ └── Request.php ├── CompanyPay │ ├── Bank │ │ ├── Pay │ │ │ └── Request.php │ │ └── Query │ │ │ └── Request.php │ └── Weixin │ │ ├── Pay │ │ └── Request.php │ │ └── Query │ │ └── Request.php ├── CustomDeclareOrder │ └── Request.php ├── CustomDeclareQuery │ └── Request.php ├── DownloadBill │ └── Request.php ├── ExchageRate │ └── Request.php ├── GetPublicKey │ └── Request.php ├── H5 │ └── Params │ │ ├── Pay │ │ └── Request.php │ │ └── SceneInfo.php ├── JSAPI │ └── Params │ │ ├── JSParams │ │ └── Request.php │ │ ├── Pay │ │ └── Request.php │ │ └── SceneInfo.php ├── Micropay │ └── Params │ │ ├── Pay │ │ └── Request.php │ │ └── SceneInfo.php ├── Native │ └── Params │ │ ├── Pay │ │ ├── Mode1Request.php │ │ └── Request.php │ │ └── SceneInfo.php ├── Notify │ ├── Base.php │ ├── BaseV3.php │ ├── Pay.php │ ├── PayMode1.php │ └── Refund.php ├── OrderQuery │ └── Request.php ├── Params │ ├── Detail.php │ ├── GoodsDetail.php │ ├── PayRequestBase.php │ └── PublicParams.php ├── Profit │ ├── AddReceiver │ │ └── Request.php │ ├── AdderReceiver.php │ ├── AmountQuery │ │ └── Request.php │ ├── Finish │ │ └── Request.php │ ├── MerchantRatioQuery │ │ └── Request.php │ ├── MultiProfitSharing │ │ └── Request.php │ ├── ProfitSharing │ │ └── Request.php │ ├── ProfitSharingQuery │ │ └── Request.php │ ├── ProfitSharingReceiver.php │ ├── ProfitSharingReturn │ │ └── Request.php │ ├── RemoveReceiver │ │ └── Request.php │ ├── RemoverReceiver.php │ └── ReturnQuery │ │ └── Request.php ├── QueryComment │ └── Request.php ├── Refund │ └── Request.php ├── RefundQuery │ └── Request.php ├── Reply │ ├── Base.php │ ├── BaseV3.php │ ├── Pay.php │ └── PayMode1.php ├── Report │ ├── Request.php │ └── Trades.php ├── Reverse │ └── Request.php ├── SDK.php ├── SDKV3.php ├── SettlementQuery │ └── Request.php ├── Shorturl │ └── Request.php ├── Tool │ └── CertificateDownloader.php └── V3 │ └── Certificates │ └── Request.php ├── WeixinRequestBase.php └── WeixinRequestBaseV3.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 宇润 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yurunsoft/pay-sdk", 3 | "description": "PHP 集成支付 SDK ,集成了支付宝、微信支付的支付接口和其它相关接口的操作。", 4 | "type": "library", 5 | "license": "MIT", 6 | "autoload": { 7 | "psr-4": { 8 | "Yurun\\PaySDK\\": "src/" 9 | } 10 | }, 11 | "require": { 12 | "php": ">=5.5", 13 | "yurunsoft/yurun-http" : "~4.0|~5.0" 14 | }, 15 | "require-dev": { 16 | "friendsofphp/php-cs-fixer": "2.18.3" 17 | }, 18 | "bin": [ 19 | "src/Weixin/Tool/CertificateDownloader.php" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/Alipay/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 44 | $this->_method = 'GET'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Alipay/Params/PublicParams.php: -------------------------------------------------------------------------------- 1 | apiDomain = 'https://mapi.alipay.com/gateway.do'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Alipay/Params/Refund/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 45 | $this->_method = 'GET'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Alipay/Params/RefundPwd/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Alipay/Params/WapPay/ExtUserInfo.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 44 | $this->_method = 'GET'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/AlipayApp/Agreement/Params/Modify/BusinessParams.php: -------------------------------------------------------------------------------- 1 | $value) { 34 | if (null === $value) { 35 | unset($obj[$key]); 36 | } 37 | } 38 | 39 | return json_encode($obj); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AlipayApp/Agreement/Params/Modify/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 30 | $this->_method = 'GET'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/AlipayApp/Agreement/Params/Query/BusinessParams.php: -------------------------------------------------------------------------------- 1 | $value) 70 | { 71 | if (null === $value) 72 | { 73 | unset($obj[$key]); 74 | } 75 | } 76 | 77 | return json_encode($obj); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/AlipayApp/Agreement/Params/Query/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 30 | $this->_method = 'GET'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/AlipayApp/Agreement/Params/Sign/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 44 | $this->_method = 'GET'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/AlipayApp/Agreement/Params/UnSign/BusinessParams.php: -------------------------------------------------------------------------------- 1 | $value) { 94 | if (null === $value) { 95 | unset($obj[$key]); 96 | } 97 | } 98 | 99 | return json_encode($obj); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/AlipayApp/Agreement/Params/UnSign/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 30 | $this->_method = 'GET'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/AlipayApp/App/ExtUserInfo.php: -------------------------------------------------------------------------------- 1 | extend_params = new ExtendParams(); 119 | } 120 | 121 | public function toString() 122 | { 123 | $obj = (array) $this; 124 | $result = $obj['extend_params']->toArray(); 125 | if (null === $result) 126 | { 127 | unset($obj['extend_params']); 128 | } 129 | else 130 | { 131 | $obj['extend_params'] = $result; 132 | } 133 | foreach ($obj as $key => $value) 134 | { 135 | if (null === $value) 136 | { 137 | unset($obj[$key]); 138 | } 139 | } 140 | 141 | return json_encode($obj); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/AlipayApp/App/Params/Pay/ExtendParams.php: -------------------------------------------------------------------------------- 1 | sys_service_provider_id && null === $this->hb_fq_num && null === $this->hb_fq_seller_percent && null === $this->needBuyerRealnamed && null === $this->TRANS_MEMO) 51 | { 52 | return null; 53 | } 54 | 55 | return (array) $this; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/AlipayApp/App/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/AlipayApp/FTF/Params/ExtendParams.php: -------------------------------------------------------------------------------- 1 | sys_service_provider_id) 20 | { 21 | return null; 22 | } 23 | 24 | return (array) $this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/AlipayApp/FTF/Params/GoodsDetail.php: -------------------------------------------------------------------------------- 1 | 91 | */ 92 | public $goods_detail; 93 | 94 | /** 95 | * 业务扩展参数,详见业务扩展参数说明. 96 | * 97 | * @var \Yurun\PaySDK\AlipayApp\FTF\Params\ExtendParams 98 | */ 99 | public $extend_params; 100 | 101 | /** 102 | * 商户操作员编号. 103 | * 104 | * @var string 105 | */ 106 | public $operator_id; 107 | 108 | /** 109 | * 商户门店编号. 110 | * 111 | * @var string 112 | */ 113 | public $store_id; 114 | 115 | /** 116 | * 商户机具终端编号. 117 | * 118 | * @var string 119 | */ 120 | public $terminal_id; 121 | 122 | /** 123 | * 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m. 124 | * 125 | * @var string 126 | */ 127 | public $timeout_express; 128 | 129 | public function __construct() 130 | { 131 | $this->extend_params = new ExtendParams(); 132 | } 133 | 134 | public function toString() 135 | { 136 | $obj = (array) $this; 137 | if (empty($obj['goods_detail'])) 138 | { 139 | unset($obj['goods_detail']); 140 | } 141 | else 142 | { 143 | $obj['goods_detail'] = json_encode($obj['goods_detail']); 144 | } 145 | $result = $obj['extend_params']->toArray(); 146 | if (null === $result) 147 | { 148 | unset($obj['extend_params']); 149 | } 150 | else 151 | { 152 | $obj['extend_params'] = $result; 153 | } 154 | foreach ($obj as $key => $value) 155 | { 156 | if (null === $value) 157 | { 158 | unset($obj[$key]); 159 | } 160 | } 161 | 162 | return json_encode($obj); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/AlipayApp/FTF/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 44 | $this->_method = 'GET'; 45 | $this->_isSyncVerify = true; 46 | $this->_syncResponseName = 'alipay_trade_pay_response'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/AlipayApp/FTF/Params/QR/BusinessParams.php: -------------------------------------------------------------------------------- 1 | 61 | */ 62 | public $goods_detail; 63 | 64 | /** 65 | * 业务扩展参数,详见业务扩展参数说明. 66 | * 67 | * @var \Yurun\PaySDK\AlipayApp\FTF\Params\ExtendParams 68 | */ 69 | public $extend_params; 70 | 71 | /** 72 | * 商户操作员编号. 73 | * 74 | * @var string 75 | */ 76 | public $operator_id; 77 | 78 | /** 79 | * 商户门店编号. 80 | * 81 | * @var string 82 | */ 83 | public $store_id; 84 | 85 | /** 86 | * 商户机具终端编号. 87 | * 88 | * @var string 89 | */ 90 | public $terminal_id; 91 | 92 | /** 93 | * 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m. 94 | * 95 | * @var string 96 | */ 97 | public $timeout_express; 98 | 99 | /** 100 | * 禁用渠道. 101 | * 102 | * @var string 103 | */ 104 | public $disable_pay_channels; 105 | 106 | /** 107 | * 指定支付渠道. 108 | * 109 | * @var string 110 | */ 111 | public $enable_pay_channels; 112 | 113 | public function __construct() 114 | { 115 | $this->extend_params = new ExtendParams(); 116 | } 117 | 118 | public function toString() 119 | { 120 | $obj = (array) $this; 121 | if (empty($obj['goods_detail'])) 122 | { 123 | unset($obj['goods_detail']); 124 | } 125 | else 126 | { 127 | $obj['goods_detail'] = json_encode($obj['goods_detail']); 128 | } 129 | $result = $obj['extend_params']->toArray(); 130 | if (null === $result) 131 | { 132 | unset($obj['extend_params']); 133 | } 134 | else 135 | { 136 | $obj['extend_params'] = $result; 137 | } 138 | foreach ($obj as $key => $value) 139 | { 140 | if (null === $value) 141 | { 142 | unset($obj[$key]); 143 | } 144 | } 145 | 146 | return json_encode($obj); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/AlipayApp/FTF/Params/QR/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 44 | $this->_method = 'GET'; 45 | $this->_isSyncVerify = true; 46 | $this->_syncResponseName = 'alipay_trade_precreate_response'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/AlipayApp/Fund/Query/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/AlipayApp/Fund/Transfer/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/AlipayApp/Fund/UniTransfer/BusinessParams.php: -------------------------------------------------------------------------------- 1 | 53 | */ 54 | public $payee_info = array(); 55 | 56 | /** 57 | * 业务备注 58 | * @var string 59 | */ 60 | public $remark; 61 | 62 | /** 63 | * 转账业务请求的扩展参数,支持传入的扩展参数如下: 64 | * sub_biz_scene 子业务场景,红包业务必传,取值REDPACKET,C2C现金红包、B2C现金红包均需传入 65 | * @return array 66 | */ 67 | public $business_params = array(); 68 | 69 | public function toString() 70 | { 71 | $obj = (array)$this; 72 | 73 | if (empty($obj['payee_info'])) { 74 | unset($obj['payee_info']); 75 | } else { 76 | $obj['payee_info'] = \json_encode($obj['payee_info']); 77 | } 78 | 79 | if (empty($obj['business_params'])) { 80 | unset($obj['business_params']); 81 | } else { 82 | $obj['business_params'] = \json_encode($obj['business_params']); 83 | } 84 | 85 | foreach ($obj as $key => $value) { 86 | if (null === $value) { 87 | unset($obj[$key]); 88 | } 89 | } 90 | 91 | return \json_encode($obj); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/AlipayApp/Fund/UniTransfer/PayeeInfoParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams; 32 | $this->_method = 'GET'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/AlipayApp/MiniApp/Params/Pay/ExtendParams.php: -------------------------------------------------------------------------------- 1 | sys_service_provider_id && null === $this->card_type) 27 | { 28 | return null; 29 | } 30 | 31 | return (array) $this; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/AlipayApp/MiniApp/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 44 | $this->_method = 'GET'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/AlipayApp/Page/Params/GoodsDetail.php: -------------------------------------------------------------------------------- 1 | show_url) 20 | { 21 | return null; 22 | } 23 | 24 | return (array) $this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/AlipayApp/Page/Params/Pay/ExtendParams.php: -------------------------------------------------------------------------------- 1 | sys_service_provider_id && null === $this->hb_fq_num && null === $this->hb_fq_seller_percent) 34 | { 35 | return null; 36 | } 37 | 38 | return (array) $this; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/AlipayApp/Page/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 51 | $this->_method = 'GET'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/Cancel/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | $this->_isSyncVerify = true; 39 | $this->_syncResponseName = 'alipay_trade_cancel_response'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/Close/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | $this->_isSyncVerify = true; 39 | $this->_syncResponseName = 'alipay_trade_close_response'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/DownloadBill/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | $this->_isSyncVerify = true; 39 | $this->_syncResponseName = 'alipay_data_dataservice_bill_downloadurl_query_response'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/PublicParams.php: -------------------------------------------------------------------------------- 1 | =5.4.8下才可使用。 29 | * 30 | * @var string 31 | */ 32 | public $sign_type = 'RSA2'; 33 | 34 | /** 35 | * 调用的接口版本,固定为:1.0. 36 | * 37 | * @var string 38 | */ 39 | public $version = '1.0'; 40 | 41 | /** 42 | * 私有证书文件内容. 43 | * 44 | * @var string 45 | */ 46 | public $appPrivateKey; 47 | 48 | /** 49 | * 私有证书文件地址,不为空时优先使用文件地址 50 | * 51 | * @var string 52 | */ 53 | public $appPrivateKeyFile; 54 | 55 | /** 56 | * 公有证书文件内容. 57 | * 58 | * @var string 59 | */ 60 | public $appPublicKey; 61 | 62 | /** 63 | * 公有证书文件地址,不为空时优先使用文件地址 64 | * 65 | * @var string 66 | */ 67 | public $appPublicKeyFile; 68 | 69 | /** 70 | * 是否使用AES加密解密数据. 71 | * 72 | * @var bool 73 | */ 74 | public $isUseAES = false; 75 | 76 | /** 77 | * AES密钥. 78 | * 79 | * @var string 80 | */ 81 | public $aesKey; 82 | 83 | /** 84 | * 是否使用公钥证书模式. 85 | * 86 | * @var bool 87 | */ 88 | public $usePublicKeyCert = false; 89 | 90 | /** 91 | * 支付宝公钥证书文件路径. 92 | * 93 | * @var string 94 | */ 95 | public $alipayCertPath; 96 | 97 | /** 98 | * 支付宝根证书文件路径. 99 | * 100 | * @var string 101 | */ 102 | public $alipayRootCertPath; 103 | 104 | /** 105 | * 支付宝应用公钥证书文件路径. 106 | * 107 | * @var string 108 | */ 109 | public $merchantCertPath; 110 | 111 | public function __construct() 112 | { 113 | $this->apiDomain = 'https://openapi.alipay.com/gateway.do'; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/Query/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | $this->_isSyncVerify = true; 39 | $this->_syncResponseName = 'alipay_trade_query_response'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/Refund/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | $this->_isSyncVerify = true; 39 | $this->_syncResponseName = 'alipay_trade_refund_response'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/RefundQuery/BusinessParams.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | $this->_isSyncVerify = true; 39 | $this->_syncResponseName = 'alipay_trade_fastpay_refund_query_response'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/Settle/BusinessParams.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | public $royalty_parameters = []; 32 | 33 | /** 34 | * 操作员id. 35 | * 36 | * @var string 37 | */ 38 | public $operator_id; 39 | 40 | public function toString() 41 | { 42 | $obj = (array) $this; 43 | if (empty($obj['royalty_parameters'])) 44 | { 45 | unset($obj['royalty_parameters']); 46 | } 47 | else 48 | { 49 | $obj['royalty_parameters'] = json_encode($obj['royalty_parameters']); 50 | } 51 | 52 | return json_encode($obj); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/Settle/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 37 | $this->_method = 'GET'; 38 | $this->_isSyncVerify = true; 39 | $this->_syncResponseName = 'alipay_trade_order_settle_response'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/AlipayApp/Params/Settle/RoyaltyParameter.php: -------------------------------------------------------------------------------- 1 | extend_params = new ExtendParams(); 142 | } 143 | 144 | public function toString() 145 | { 146 | $obj = (array) $this; 147 | $result = $obj['extend_params']->toArray(); 148 | if (null === $result) 149 | { 150 | unset($obj['extend_params']); 151 | } 152 | else 153 | { 154 | $obj['extend_params'] = $result; 155 | } 156 | foreach ($obj as $key => $value) 157 | { 158 | if (null === $value) 159 | { 160 | unset($obj[$key]); 161 | } 162 | } 163 | 164 | return json_encode($obj); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/AlipayApp/Wap/Params/Pay/ExtendParams.php: -------------------------------------------------------------------------------- 1 | sys_service_provider_id && null === $this->hb_fq_num && null === $this->hb_fq_seller_percent && null === $this->needBuyerRealnamed && null === $this->TRANS_MEMO) 51 | { 52 | return null; 53 | } 54 | 55 | return (array) $this; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/AlipayApp/Wap/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | businessParams = new BusinessParams(); 51 | $this->_method = 'GET'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Customs/Query/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 30 | $this->_isSyncVerify = true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Customs/Submit/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 94 | $this->_isSyncVerify = true; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/InStore/BarcodePay/ExtendInfo.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 108 | $this->_isSyncVerify = true; 109 | $this->extend_info = new ExtendInfo(); 110 | } 111 | 112 | public function toArray() 113 | { 114 | $obj = (array) $this; 115 | if (empty($obj['extend_info'])) 116 | { 117 | unset($obj['extend_info']); 118 | } 119 | else 120 | { 121 | $obj['extend_info'] = json_encode($obj['extend_info']); 122 | } 123 | 124 | return $obj; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/InStore/Cancel/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 50 | $this->_isSyncVerify = true; 51 | } 52 | 53 | public function toArray() 54 | { 55 | $obj = (array) $this; 56 | if (empty($obj['timestamp'])) 57 | { 58 | $obj['timestamp'] = round(microtime(true) * 1000); 59 | } 60 | 61 | return $obj; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/InStore/CreateMerchantQR/BizData.php: -------------------------------------------------------------------------------- 1 | channel_fee = new \Yurun\PaySDK\AlipayCrossBorder\InStore\CreateMerchantQR\ChannelFee(); 151 | } 152 | 153 | public function toArray() 154 | { 155 | $obj = (array) $this; 156 | if (empty($obj['passback_parameters'])) 157 | { 158 | unset($obj['passback_parameters']); 159 | } 160 | if (empty($obj['channel_fee']->type)) 161 | { 162 | unset($obj['channel_fee']); 163 | } 164 | foreach ($obj as $key => $value) 165 | { 166 | if (null === $value) 167 | { 168 | unset($obj[$key]); 169 | } 170 | } 171 | 172 | return $obj; 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/InStore/CreateMerchantQR/ChannelFee.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 51 | $this->_isSyncVerify = true; 52 | $this->biz_data = new \Yurun\PaySDK\AlipayCrossBorder\InStore\CreateMerchantQR\BizData(); 53 | } 54 | 55 | public function toArray() 56 | { 57 | $obj = (array) $this; 58 | if (empty($obj['timestamp'])) 59 | { 60 | $obj['timestamp'] = date('Y-m-d H:i:s'); 61 | } 62 | $obj['biz_data'] = json_encode(ObjectToArray::parse($obj['biz_data'])); 63 | 64 | return $obj; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/InStore/ModifyMerchantQR/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 60 | $this->_isSyncVerify = true; 61 | } 62 | 63 | public function toArray() 64 | { 65 | $obj = (array) $this; 66 | if (empty($obj['timestamp'])) 67 | { 68 | $obj['timestamp'] = date('Y-m-d H:i:s'); 69 | } 70 | 71 | return $obj; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/InStore/PreCreate/ExtendInfo.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 36 | $this->_isSyncVerify = true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/InStore/Refund/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 71 | $this->_isSyncVerify = true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/DownloadCompare/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/DownloadSettlement/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/ExchageRate/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/Notify/Base.php: -------------------------------------------------------------------------------- 1 | swooleResponse) 32 | { 33 | echo $result; 34 | } 35 | elseif ($this->swooleResponse instanceof \Swoole\Http\Response) 36 | { 37 | $this->swooleResponse->end($result); 38 | } 39 | elseif ($this->swooleResponse instanceof \Psr\Http\Message\ResponseInterface) 40 | { 41 | $this->swooleResponse = $this->swooleResponse->withBody(new MemoryStream($result)); 42 | } 43 | } 44 | } 45 | 46 | /** 47 | * 获取通知数据. 48 | * 49 | * @return array|mixed 50 | */ 51 | public function getNotifyData() 52 | { 53 | if ($this->swooleRequest instanceof \Swoole\Http\Request) 54 | { 55 | return $this->swooleRequest->post; 56 | } 57 | if ($this->swooleRequest instanceof \Psr\Http\Message\ServerRequestInterface) 58 | { 59 | return $this->swooleRequest->getParsedBody(); 60 | } 61 | 62 | return $_POST; 63 | } 64 | 65 | /** 66 | * 对通知进行验证,是否是正确的通知. 67 | * 68 | * @return bool 69 | */ 70 | public function notifyVerify() 71 | { 72 | return $this->sdk->verifyCallback($this->data); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/Notify/Pay.php: -------------------------------------------------------------------------------- 1 | notify_id = $this->data['notify_id']; 19 | 20 | return 'true' === $this->sdk->execute($request, ''); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/Notify/Sync.php: -------------------------------------------------------------------------------- 1 | swooleRequest instanceof \Swoole\Http\Request) 18 | { 19 | return $this->swooleRequest->get; 20 | } 21 | if ($this->swooleRequest instanceof \Psr\Http\Message\ServerRequestInterface) 22 | { 23 | return $this->swooleRequest->getQueryParams(); 24 | } 25 | 26 | return $_GET; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/NotifyVerify/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/Pay/Request.php: -------------------------------------------------------------------------------- 1 | 144 | */ 145 | public $split_fund_info = []; 146 | 147 | public function __construct() 148 | { 149 | $this->_method = 'GET'; 150 | } 151 | 152 | public function toArray() 153 | { 154 | $obj = (array) $this; 155 | if (empty($obj['split_fund_info'])) 156 | { 157 | unset($obj['split_fund_info']); 158 | } 159 | else 160 | { 161 | $obj['split_fund_info'] = json_encode($obj['split_fund_info']); 162 | } 163 | 164 | return $obj; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/Query/Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 38 | $this->_isSyncVerify = true; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/Refund/Request.php: -------------------------------------------------------------------------------- 1 | 81 | */ 82 | public $split_fund_info = []; 83 | 84 | public function __construct() 85 | { 86 | $this->_method = 'GET'; 87 | $this->_isSyncVerify = true; 88 | } 89 | 90 | public function toArray() 91 | { 92 | $obj = (array) $this; 93 | if (empty($obj['split_fund_info'])) 94 | { 95 | unset($obj['split_fund_info']); 96 | } 97 | else 98 | { 99 | $obj['split_fund_info'] = json_encode($obj['split_fund_info']); 100 | } 101 | 102 | return $obj; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Online/WapPay/Request.php: -------------------------------------------------------------------------------- 1 | 151 | */ 152 | public $split_fund_info = []; 153 | 154 | public function __construct() 155 | { 156 | $this->_method = 'GET'; 157 | } 158 | 159 | public function toArray() 160 | { 161 | $obj = (array) $this; 162 | if (empty($obj['split_fund_info'])) 163 | { 164 | unset($obj['split_fund_info']); 165 | } 166 | else 167 | { 168 | $obj['split_fund_info'] = json_encode($obj['split_fund_info']); 169 | } 170 | 171 | return $obj; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Params/PublicParams.php: -------------------------------------------------------------------------------- 1 | apiDomain = 'https://mapi.alipay.com/gateway.do'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/AlipayCrossBorder/Params/SplitFundInfo.php: -------------------------------------------------------------------------------- 1 | $value) 76 | { 77 | $string[] = $key . '=' . $value; 78 | } 79 | } 80 | 81 | return implode(',', $string); 82 | } 83 | 84 | /** 85 | * 0x转高精度数字. 86 | * 87 | * @param $hex 88 | * 89 | * @return int|string 90 | */ 91 | public static function hex2dec($hex) 92 | { 93 | $dec = 0; 94 | $len = \strlen($hex); 95 | for ($i = 3; $i <= $len; ++$i) 96 | { 97 | $dec = bcadd($dec, bcmul((string) (hexdec($hex[$i - 1])), bcpow('16', (string) ($len - $i)))); 98 | } 99 | 100 | return $dec; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Lib/Encrypt/AES.php: -------------------------------------------------------------------------------- 1 | = PHP 7.2) 37 | if (\function_exists('\sodium_crypto_aead_aes256gcm_is_available') && 38 | sodium_crypto_aead_aes256gcm_is_available()) 39 | { 40 | return sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey); 41 | } 42 | 43 | // ext-libsodium (need install libsodium-php 1.x via pecl) 44 | if (\function_exists('\Sodium\crypto_aead_aes256gcm_is_available') && 45 | \Sodium\crypto_aead_aes256gcm_is_available()) 46 | { 47 | return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey); 48 | } 49 | 50 | // openssl (PHP >= 7.1 support AEAD) 51 | if (\PHP_VERSION_ID >= 70100 && \in_array('aes-256-gcm', openssl_get_cipher_methods())) 52 | { 53 | $ctext = substr($ciphertext, 0, -self::AUTH_TAG_LENGTH_BYTE); 54 | $authTag = substr($ciphertext, -self::AUTH_TAG_LENGTH_BYTE); 55 | 56 | return openssl_decrypt($ctext, 'aes-256-gcm', $aesKey, \OPENSSL_RAW_DATA, $nonceStr, 57 | $authTag, $associatedData); 58 | } 59 | 60 | throw new \RuntimeException('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php'); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Lib/Encrypt/Base.php: -------------------------------------------------------------------------------- 1 | =5.4.8下才可使用'); 12 | } 13 | $key = static::parseKey($key); 14 | $key = "-----BEGIN RSA PRIVATE KEY-----\n{$key}\n-----END RSA PRIVATE KEY-----"; 15 | openssl_sign($data, $sign, $key, \OPENSSL_ALGO_SHA256); 16 | 17 | return $sign; 18 | } 19 | 20 | public static function signPrivateFromFile($data, $fileName) 21 | { 22 | if (!\defined('OPENSSL_ALGO_SHA256')) 23 | { 24 | throw new \Exception('SHA256需要在PHP>=5.4.8下才可使用'); 25 | } 26 | $key = file_get_contents($fileName); 27 | $res = openssl_get_privatekey($key); 28 | if (!$res) 29 | { 30 | throw new \Exception('私钥文件格式错误'); 31 | } 32 | openssl_sign($data, $sign, $res, \OPENSSL_ALGO_SHA256); 33 | if (PHP_VERSION_ID < 80000) 34 | { 35 | openssl_free_key($res); 36 | } 37 | 38 | return $sign; 39 | } 40 | 41 | public static function verifyPublic($data, $key, $sign) 42 | { 43 | if (!\defined('OPENSSL_ALGO_SHA256')) 44 | { 45 | throw new \Exception('SHA256需要在PHP>=5.4.8下才可使用'); 46 | } 47 | $key = static::parseKey($key); 48 | $key = "-----BEGIN PUBLIC KEY-----\n{$key}\n-----END PUBLIC KEY-----"; 49 | 50 | return 1 === openssl_verify($data, $sign, $key, \OPENSSL_ALGO_SHA256); 51 | } 52 | 53 | public static function verifyPublicFromFile($data, $fileName, $sign) 54 | { 55 | if (!\defined('OPENSSL_ALGO_SHA256')) 56 | { 57 | throw new \Exception('SHA256需要在PHP>=5.4.8下才可使用'); 58 | } 59 | $key = file_get_contents($fileName); 60 | $res = openssl_get_publickey($key); 61 | if (!$res) 62 | { 63 | throw new \Exception('公钥文件格式错误'); 64 | } 65 | $result = openssl_verify($data, $sign, $res, \OPENSSL_ALGO_SHA256); 66 | if (PHP_VERSION_ID < 80000) 67 | { 68 | openssl_free_key($res); 69 | } 70 | 71 | return 1 === $result; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Lib/Encrypt/SHA256withRSA/SignatureResult.php: -------------------------------------------------------------------------------- 1 | sign = $sign; 30 | $this->certificateSerialNumber = $serialNumber; 31 | } 32 | 33 | /** 34 | * Get Signature. 35 | * 36 | * @return string 37 | */ 38 | public function getSign() 39 | { 40 | return $this->sign; 41 | } 42 | 43 | /** 44 | * Get Certificate Serial Number. 45 | * 46 | * @return string 47 | */ 48 | public function getCertificateSerialNumber() 49 | { 50 | return $this->certificateSerialNumber; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Lib/Encrypt/SHA256withRSA/Signer.php: -------------------------------------------------------------------------------- 1 | toArray(); 19 | } 20 | else 21 | { 22 | return get_object_vars($object); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Lib/Util.php: -------------------------------------------------------------------------------- 1 | = 80000) { 11 | return (array) simplexml_load_string($string, null, \LIBXML_NOCDATA | \LIBXML_COMPACT); 12 | } 13 | 14 | // 填补 php <= 5.4 的安全漏洞:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=23_5 15 | // 记录旧值 16 | $oldValue = libxml_disable_entity_loader(true); 17 | // xml解析 18 | $result = (array) simplexml_load_string($string, null, \LIBXML_NOCDATA | \LIBXML_COMPACT); 19 | // 恢复旧值,防止系统中其它需要用到实体加载的地方失效 20 | if (false === $oldValue) 21 | { 22 | libxml_disable_entity_loader(false); 23 | } 24 | 25 | return $result; 26 | } 27 | 28 | public static function toString($data) 29 | { 30 | $result = ''; 31 | if (\is_object($data)) 32 | { 33 | $_data = ObjectToArray::parse($data); 34 | } 35 | else 36 | { 37 | $_data = &$data; 38 | } 39 | foreach ($_data as $key => $value) 40 | { 41 | if (!is_scalar($value)) 42 | { 43 | if (\is_object($value) && method_exists($value, 'toString')) 44 | { 45 | $value = $value->toString(); 46 | if (null === $value) 47 | { 48 | continue; 49 | } 50 | } 51 | elseif (null !== $value) 52 | { 53 | $value = json_encode($value); 54 | } 55 | else 56 | { 57 | continue; 58 | } 59 | } 60 | $result .= "<{$key}>"; 61 | } 62 | 63 | return $result . ''; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/NotifyBase.php: -------------------------------------------------------------------------------- 1 | data = $this->getNotifyData(); 57 | if (!$this->notifyVerify()) 58 | { 59 | $this->reply(false, '通知不合法'); 60 | throw new \Exception('通知不合法'); 61 | } 62 | $this->__exec(); 63 | } 64 | 65 | /** 66 | * 返回数据. 67 | * 68 | * @param bool $success 69 | * @param string $message 70 | * 71 | * @return void 72 | */ 73 | abstract public function reply($success, $message = ''); 74 | 75 | /** 76 | * 获取通知数据. 77 | * 78 | * @return mixed 79 | */ 80 | abstract public function getNotifyData(); 81 | 82 | /** 83 | * 对通知进行验证,是否是正确的通知. 84 | * 85 | * @return bool 86 | */ 87 | abstract public function notifyVerify(); 88 | 89 | /** 90 | * 后续执行操作. 91 | * 92 | * @return void 93 | */ 94 | abstract protected function __exec(); 95 | } 96 | -------------------------------------------------------------------------------- /src/PublicBase.php: -------------------------------------------------------------------------------- 1 | toString(); 10 | } 11 | 12 | public function toString() 13 | { 14 | return http_build_query($this, '', '&'); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Traits/JSONParams.php: -------------------------------------------------------------------------------- 1 | toString(); 10 | if (\is_string($result)) 11 | { 12 | return $result; 13 | } 14 | else 15 | { 16 | return ''; 17 | } 18 | } 19 | 20 | public function toString() 21 | { 22 | return json_encode($this); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Traits/XMLParams.php: -------------------------------------------------------------------------------- 1 | toString(); 12 | } 13 | 14 | public function toString() 15 | { 16 | return XML::toString($this); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Weixin/APP/Params/Client/Request.php: -------------------------------------------------------------------------------- 1 | needMchID = false; 56 | $this->needSignType = false; 57 | } 58 | 59 | public function toArray() 60 | { 61 | $data = get_object_vars($this); 62 | if (!isset($data['timestamp'])) 63 | { 64 | $data['timestamp'] = Util::getBeijingTime(); 65 | } 66 | 67 | return $data; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Weixin/APP/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | trade_type = 'APP'; 37 | $this->scene_info = new SceneInfo(); 38 | parent::__construct(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Weixin/APP/Params/SceneInfo.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = $this->needSignType = $this->needAppID = false; 80 | } 81 | 82 | public function toArray() 83 | { 84 | $data = get_object_vars($this); 85 | if ($this->rsaPublicCertFile) 86 | { 87 | $method = 'encryptPublicFromFile'; 88 | $public = $this->rsaPublicCertFile; 89 | } 90 | else 91 | { 92 | $method = 'encryptPublic'; 93 | $public = $this->rsaPublicCertContent; 94 | } 95 | $data['enc_bank_no'] = base64_encode(RSA::$method($data['enc_bank_no'], $public)); 96 | $data['enc_true_name'] = base64_encode(RSA::$method($data['enc_true_name'], $public)); 97 | 98 | return $data; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Weixin/CompanyPay/Bank/Query/Request.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = $this->needSignType = $this->needAppID = false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Weixin/CompanyPay/Weixin/Pay/Request.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = $this->needSignType = false; 96 | $this->signType = 'MD5'; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Weixin/CompanyPay/Weixin/Query/Request.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = $this->needSignType = false; 30 | $this->signType = 'MD5'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Weixin/CustomDeclareOrder/Request.php: -------------------------------------------------------------------------------- 1 | needNonceStr = $this->needSignType = false; 131 | $this->signType = 'MD5'; 132 | parent::__construct(); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/Weixin/CustomDeclareQuery/Request.php: -------------------------------------------------------------------------------- 1 | needNonceStr = $this->needSignType = false; 71 | $this->signType = 'MD5'; 72 | parent::__construct(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Weixin/DownloadBill/Request.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = false; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Weixin/ExchageRate/Request.php: -------------------------------------------------------------------------------- 1 | needNonceStr = $this->needSignType = false; 43 | $this->signType = 'MD5'; 44 | parent::__construct(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Weixin/GetPublicKey/Request.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = $this->needAppID = false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Weixin/H5/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | trade_type = 'MWEB'; 44 | $this->scene_info = new SceneInfo(); 45 | parent::__construct(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Weixin/H5/Params/SceneInfo.php: -------------------------------------------------------------------------------- 1 | $this->type, 61 | ]; 62 | switch ($this->type) 63 | { 64 | case 'IOS': 65 | $data['app_name'] = $this->app_name; 66 | $data['bundle_id'] = $this->bundle_id; 67 | break; 68 | case 'Android': 69 | $data['app_name'] = $this->app_name; 70 | $data['package_name'] = $this->package_name; 71 | break; 72 | case 'Wap': 73 | $data['wap_url'] = $this->wap_url; 74 | $data['wap_name'] = $this->wap_name; 75 | break; 76 | default: 77 | return ''; 78 | } 79 | 80 | return json_encode(['h5_info' => $data]); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Weixin/JSAPI/Params/JSParams/Request.php: -------------------------------------------------------------------------------- 1 | $sdk->publicParams->appID, 32 | 'timeStamp' => (string) (Util::getBeijingTime()), 33 | 'nonceStr' => md5(mt_rand()), 34 | 'package' => 'prepay_id=' . $this->prepay_id, 35 | 'signType' => $sdk->publicParams->sign_type, 36 | ]; 37 | $data['paySign'] = $sdk->sign($data); 38 | $sdk->result = $data; 39 | 40 | return true; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Weixin/JSAPI/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | trade_type = 'JSAPI'; 37 | $this->scene_info = new SceneInfo(); 38 | parent::__construct(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Weixin/JSAPI/Params/SceneInfo.php: -------------------------------------------------------------------------------- 1 | id && null === $this->name && null === $this->area_code && null === $this->address) 47 | { 48 | return null; 49 | } 50 | else 51 | { 52 | return $this->traitToString(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Weixin/Micropay/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | scene_info = new SceneInfo(); 37 | parent::__construct(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Weixin/Micropay/Params/SceneInfo.php: -------------------------------------------------------------------------------- 1 | id && null === $this->name && null === $this->area_code && null === $this->address) 47 | { 48 | return null; 49 | } 50 | else 51 | { 52 | return $this->traitToString(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Weixin/Native/Params/Pay/Mode1Request.php: -------------------------------------------------------------------------------- 1 | _method = 'GET'; 38 | parent::__construct(); 39 | $this->time_stamp = Util::getBeijingTime(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Weixin/Native/Params/Pay/Request.php: -------------------------------------------------------------------------------- 1 | trade_type = 'NATIVE'; 37 | $this->scene_info = new SceneInfo(); 38 | parent::__construct(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Weixin/Native/Params/SceneInfo.php: -------------------------------------------------------------------------------- 1 | id && null === $this->name && null === $this->area_code && null === $this->address) 47 | { 48 | return null; 49 | } 50 | else 51 | { 52 | return $this->traitToString(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Weixin/Notify/Base.php: -------------------------------------------------------------------------------- 1 | replyData = new ReplyBase(); 19 | } 20 | 21 | /** 22 | * 返回数据. 23 | * 24 | * @param bool $success 25 | * @param string $message 26 | * 27 | * @return void 28 | */ 29 | public function reply($success, $message = '') 30 | { 31 | $this->replyData->return_code = $success ? 'SUCCESS' : 'FAIL'; 32 | $this->replyData->return_msg = $message; 33 | if (null === $this->swooleResponse) 34 | { 35 | echo $this->replyData; 36 | } 37 | elseif ($this->swooleResponse instanceof \Swoole\Http\Response) 38 | { 39 | $this->swooleResponse->end($this->replyData->toString()); 40 | } 41 | elseif ($this->swooleResponse instanceof \Psr\Http\Message\ResponseInterface) 42 | { 43 | $this->swooleResponse = $this->swooleResponse->withBody(new MemoryStream($this->replyData->toString())); 44 | } 45 | } 46 | 47 | /** 48 | * 获取通知数据. 49 | * 50 | * @return array|mixed 51 | */ 52 | public function getNotifyData() 53 | { 54 | if ($this->swooleRequest instanceof \Swoole\Http\Request) 55 | { 56 | return XML::fromString($this->swooleRequest->rawContent()); 57 | } 58 | if ($this->swooleRequest instanceof \Psr\Http\Message\ServerRequestInterface) 59 | { 60 | return XML::fromString((string) $this->swooleRequest->getBody()); 61 | } 62 | 63 | return XML::fromString(file_get_contents('php://input')); 64 | } 65 | 66 | /** 67 | * 对通知进行验证,是否是正确的通知. 68 | * 69 | * @return bool 70 | */ 71 | public function notifyVerify() 72 | { 73 | return $this->sdk->verifyCallback($this->data); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Weixin/Notify/Pay.php: -------------------------------------------------------------------------------- 1 | replyData = new ReplyPay(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Weixin/Notify/PayMode1.php: -------------------------------------------------------------------------------- 1 | replyData = new ReplyPayMode1(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Weixin/Notify/Refund.php: -------------------------------------------------------------------------------- 1 | replyData = new ReplyPay(); 25 | } 26 | 27 | /** 28 | * 获取通知数据. 29 | * 30 | * @return array|mixed 31 | */ 32 | public function getNotifyData() 33 | { 34 | $data = parent::getNotifyData(); 35 | if (isset($data['return_code']) && 'SUCCESS' === $data['return_code']) 36 | { 37 | $key = md5($this->sdk->publicParams->key); 38 | $data['req_info'] = XML::fromString(AES::decrypt256(base64_decode($data['req_info']), $key, \OPENSSL_RAW_DATA)); 39 | } 40 | 41 | return $data; 42 | } 43 | 44 | /** 45 | * 对通知进行验证,是否是正确的通知. 46 | * 47 | * @return bool 48 | */ 49 | public function notifyVerify() 50 | { 51 | return isset($this->data['return_code']); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Weixin/OrderQuery/Request.php: -------------------------------------------------------------------------------- 1 | 37 | */ 38 | public $goods_detail = []; 39 | 40 | public function toString() 41 | { 42 | if (null === $this->cost_price && null === $this->receipt_id && !isset($this->goods_detail[0])) 43 | { 44 | return null; 45 | } 46 | else 47 | { 48 | return $this->traitToString(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Weixin/Params/GoodsDetail.php: -------------------------------------------------------------------------------- 1 | detail = new Detail(); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/Weixin/Params/PublicParams.php: -------------------------------------------------------------------------------- 1 | apiDomain = 'https://api.mch.weixin.qq.com/'; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Weixin/Profit/AddReceiver/Request.php: -------------------------------------------------------------------------------- 1 | needAppID = false; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Weixin/Profit/Finish/Request.php: -------------------------------------------------------------------------------- 1 | needAppID = false; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Weixin/Profit/MerchantRatioQuery/Request.php: -------------------------------------------------------------------------------- 1 | needAppID = false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Weixin/Profit/MultiProfitSharing/Request.php: -------------------------------------------------------------------------------- 1 | needAppID = false; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Weixin/Profit/ProfitSharingReceiver.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = false; 55 | $this->needSignType = true; 56 | $this->signType = 'HMAC-SHA256'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Weixin/Refund/Request.php: -------------------------------------------------------------------------------- 1 | allowReport = false; 133 | $this->_isSyncVerify = false; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/Weixin/Report/Trades.php: -------------------------------------------------------------------------------- 1 | list); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Weixin/Reverse/Request.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = $this->needSignType = false; 67 | $this->signType = 'MD5'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Weixin/Shorturl/Request.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/WeixinRequestBase.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = true; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/WeixinRequestBaseV3.php: -------------------------------------------------------------------------------- 1 | _isSyncVerify = true; 65 | } 66 | } 67 | --------------------------------------------------------------------------------