├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml └── src ├── Latrell └── Wxpay │ ├── Facades │ └── Wxpay.php │ ├── Models │ ├── Base.php │ ├── BizPayUrl.php │ ├── CloseOrder.php │ ├── DownloadBill.php │ ├── JsApiPay.php │ ├── MicroPay.php │ ├── NotifyReply.php │ ├── OrderQuery.php │ ├── Refund.php │ ├── RefundQuery.php │ ├── Report.php │ ├── Results.php │ ├── Reverse.php │ ├── ShortUrl.php │ └── UnifiedOrder.php │ ├── Pay │ ├── JsApi.php │ ├── Micro.php │ ├── Native.php │ └── Refund.php │ ├── Sdk │ ├── Api.php │ └── Notify.php │ ├── Wxpay.php │ ├── WxpayException.php │ └── WxpayServiceProvider.php └── config ├── .gitkeep ├── cert ├── apiclient_cert.pem └── apiclient_key.pem └── config.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | .settings 6 | .buildpath 7 | .project -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Latrell Chan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wxpay 2 | 微信支付SDK在Laravel5封装包。 3 | 4 | 刷卡支付、微信内网页支付、扫码支付 5 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "latrell/wxpay", 3 | "description": "微信支付SDK在Laravel5封装包。", 4 | "keywords": ["L5", "Laravel 5", "Laravel", "Wxpay", "Micropay", "Wxpay SDK", "Micropay SDK"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Latrell Chan", 9 | "email": "i@latrell.me" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=5.4.0", 14 | "illuminate/support": "5.*", 15 | "illuminate/config": "5.*", 16 | "curl/curl": "1.2.*" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Latrell\\Wxpay\\": "src/Latrell/Wxpay/" 21 | } 22 | }, 23 | "minimum-stability": "stable" 24 | } 25 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Facades/Wxpay.php: -------------------------------------------------------------------------------- 1 | makeSign(); 25 | $this->values['sign'] = $sign; 26 | return $sign; 27 | } 28 | 29 | /** 30 | * 获取签名,详见签名生成算法的值 31 | * @return 值 32 | **/ 33 | public function getSign() 34 | { 35 | return $this->values['sign']; 36 | } 37 | 38 | /** 39 | * 判断签名,详见签名生成算法是否存在 40 | * @return true 或 false 41 | **/ 42 | public function isSignSet() 43 | { 44 | return array_key_exists('sign', $this->values); 45 | } 46 | 47 | /** 48 | * 输出xml字符 49 | * @throws WxPayException 50 | **/ 51 | public function toXml() 52 | { 53 | if (! is_array($this->values) || count($this->values) <= 0) { 54 | throw new WxPayException('数组数据异常!'); 55 | } 56 | 57 | $xml = ''; 58 | foreach ($this->values as $key => $val) { 59 | if (is_numeric($val)) { 60 | $xml .= '<' . $key . '>' . $val . ''; 61 | } else { 62 | $xml .= '<' . $key . '>'; 63 | } 64 | } 65 | $xml .= ''; 66 | return $xml; 67 | } 68 | 69 | /** 70 | * 将xml转为array 71 | * @param string $xml 72 | * @throws WxPayException 73 | */ 74 | public function fromXml($xml) 75 | { 76 | if (! $xml) { 77 | throw new WxPayException('xml数据异常!'); 78 | } 79 | //将XML转为array 80 | //禁止引用外部xml实体 81 | libxml_disable_entity_loader(true); 82 | $this->values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); 83 | return $this->values; 84 | } 85 | 86 | /** 87 | * 格式化参数格式化成url参数 88 | */ 89 | public function toUrlParams() 90 | { 91 | $buff = ''; 92 | foreach ($this->values as $k => $v) { 93 | if ($k != 'sign' && $v != '' && ! is_array($v)) { 94 | $buff .= $k . '=' . $v . '&'; 95 | } 96 | } 97 | 98 | $buff = trim($buff, '&'); 99 | return $buff; 100 | } 101 | 102 | /** 103 | * 生成签名 104 | * @return 签名,本函数不覆盖sign成员变量,如要设置签名需要调用setSign方法赋值 105 | */ 106 | public function makeSign() 107 | { 108 | //签名步骤一:按字典序排序参数 109 | ksort($this->values); 110 | $string = $this->toUrlParams(); 111 | //签名步骤二:在string后加入KEY 112 | $string = $string . '&key=' . Wxpay::getConfig('key'); 113 | //签名步骤三:MD5加密 114 | $string = md5($string); 115 | //签名步骤四:所有字符转为大写 116 | $result = strtoupper($string); 117 | return $result; 118 | } 119 | 120 | /** 121 | * 获取设置的值 122 | */ 123 | public function getValues() 124 | { 125 | return $this->values; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/BizPayUrl.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置支付时间戳 86 | * @param string $value 87 | **/ 88 | public function setTimeStamp($value) 89 | { 90 | $this->values['time_stamp'] = $value; 91 | } 92 | 93 | /** 94 | * 获取支付时间戳的值 95 | * @return 值 96 | **/ 97 | public function getTimeStamp() 98 | { 99 | return $this->values['time_stamp']; 100 | } 101 | 102 | /** 103 | * 判断支付时间戳是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isTimeStampSet() 107 | { 108 | return array_key_exists('time_stamp', $this->values); 109 | } 110 | 111 | /** 112 | * 设置随机字符串 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取随机字符串的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断随机字符串是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | 138 | /** 139 | * 设置商品ID 140 | * @param string $value 141 | **/ 142 | public function setProductId($value) 143 | { 144 | $this->values['product_id'] = $value; 145 | } 146 | 147 | /** 148 | * 获取商品ID的值 149 | * @return 值 150 | **/ 151 | public function getProductId() 152 | { 153 | return $this->values['product_id']; 154 | } 155 | 156 | /** 157 | * 判断商品ID是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isProductIdSet() 161 | { 162 | return array_key_exists('product_id', $this->values); 163 | } 164 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/CloseOrder.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置商户系统内部的订单号 86 | * @param string $value 87 | **/ 88 | public function setOutTradeNo($value) 89 | { 90 | $this->values['out_trade_no'] = $value; 91 | } 92 | 93 | /** 94 | * 获取商户系统内部的订单号的值 95 | * @return 值 96 | **/ 97 | public function getOutTradeNo() 98 | { 99 | return $this->values['out_trade_no']; 100 | } 101 | 102 | /** 103 | * 判断商户系统内部的订单号是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isOutTradeNoSet() 107 | { 108 | return array_key_exists('out_trade_no', $this->values); 109 | } 110 | 111 | /** 112 | * 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/DownloadBill.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单 86 | * @param string $value 87 | **/ 88 | public function setDeviceInfo($value) 89 | { 90 | $this->values['device_info'] = $value; 91 | } 92 | 93 | /** 94 | * 获取微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单的值 95 | * @return 值 96 | **/ 97 | public function getDeviceInfo() 98 | { 99 | return $this->values['device_info']; 100 | } 101 | 102 | /** 103 | * 判断微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isDeviceInfoSet() 107 | { 108 | return array_key_exists('device_info', $this->values); 109 | } 110 | 111 | /** 112 | * 设置随机字符串,不长于32位。推荐随机数生成算法 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | 138 | /** 139 | * 设置下载对账单的日期,格式:20140603 140 | * @param string $value 141 | **/ 142 | public function setBillDate($value) 143 | { 144 | $this->values['bill_date'] = $value; 145 | } 146 | 147 | /** 148 | * 获取下载对账单的日期,格式:20140603的值 149 | * @return 值 150 | **/ 151 | public function getBillDate() 152 | { 153 | return $this->values['bill_date']; 154 | } 155 | 156 | /** 157 | * 判断下载对账单的日期,格式:20140603是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isBillDateSet() 161 | { 162 | return array_key_exists('bill_date', $this->values); 163 | } 164 | 165 | /** 166 | * 设置ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单 167 | * @param string $value 168 | **/ 169 | public function setBillType($value) 170 | { 171 | $this->values['bill_type'] = $value; 172 | } 173 | 174 | /** 175 | * 获取ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单的值 176 | * @return 值 177 | **/ 178 | public function getBillType() 179 | { 180 | return $this->values['bill_type']; 181 | } 182 | 183 | /** 184 | * 判断ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单是否存在 185 | * @return true 或 false 186 | **/ 187 | public function isBillTypeSet() 188 | { 189 | return array_key_exists('bill_type', $this->values); 190 | } 191 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/JsApiPay.php: -------------------------------------------------------------------------------- 1 | values['appId'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appId']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appId', $this->values); 37 | } 38 | 39 | /** 40 | * 设置支付时间戳 41 | * @param string $value 42 | **/ 43 | public function setTimeStamp($value) 44 | { 45 | $this->values['timeStamp'] = (string) $value; 46 | } 47 | 48 | /** 49 | * 获取支付时间戳的值 50 | * @return 值 51 | **/ 52 | public function getTimeStamp() 53 | { 54 | return $this->values['timeStamp']; 55 | } 56 | 57 | /** 58 | * 判断支付时间戳是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isTimeStampSet() 62 | { 63 | return array_key_exists('timeStamp', $this->values); 64 | } 65 | 66 | /** 67 | * 随机字符串 68 | * @param string $value 69 | **/ 70 | public function setNonceStr($value) 71 | { 72 | $this->values['nonceStr'] = $value; 73 | } 74 | 75 | /** 76 | * 获取notify随机字符串值 77 | * @return 值 78 | **/ 79 | public function getReturnCode() 80 | { 81 | return $this->values['nonceStr']; 82 | } 83 | 84 | /** 85 | * 判断随机字符串是否存在 86 | * @return true 或 false 87 | **/ 88 | public function isReturnCodeSet() 89 | { 90 | return array_key_exists('nonceStr', $this->values); 91 | } 92 | 93 | /** 94 | * 设置订单详情扩展字符串 95 | * @param string $value 96 | **/ 97 | public function setPackage($value) 98 | { 99 | $this->values['package'] = $value; 100 | } 101 | 102 | /** 103 | * 获取订单详情扩展字符串的值 104 | * @return 值 105 | **/ 106 | public function getPackage() 107 | { 108 | return $this->values['package']; 109 | } 110 | 111 | /** 112 | * 判断订单详情扩展字符串是否存在 113 | * @return true 或 false 114 | **/ 115 | public function isPackageSet() 116 | { 117 | return array_key_exists('package', $this->values); 118 | } 119 | 120 | /** 121 | * 设置签名方式 122 | * @param string $value 123 | **/ 124 | public function setSignType($value) 125 | { 126 | $this->values['signType'] = $value; 127 | } 128 | 129 | /** 130 | * 获取签名方式 131 | * @return 值 132 | **/ 133 | public function getSignType() 134 | { 135 | return $this->values['signType']; 136 | } 137 | 138 | /** 139 | * 判断签名方式是否存在 140 | * @return true 或 false 141 | **/ 142 | public function isSignTypeSet() 143 | { 144 | return array_key_exists('signType', $this->values); 145 | } 146 | 147 | /** 148 | * 设置签名方式 149 | * @param string $value 150 | **/ 151 | public function setPaySign($value) 152 | { 153 | $this->values['paySign'] = $value; 154 | } 155 | 156 | /** 157 | * 获取签名方式 158 | * @return 值 159 | **/ 160 | public function getPaySign() 161 | { 162 | return $this->values['paySign']; 163 | } 164 | 165 | /** 166 | * 判断签名方式是否存在 167 | * @return true 或 false 168 | **/ 169 | public function isPaySignSet() 170 | { 171 | return array_key_exists('paySign', $this->values); 172 | } 173 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/MicroPay.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置终端设备号(商户自定义,如门店编号) 86 | * @param string $value 87 | **/ 88 | public function setDeviceInfo($value) 89 | { 90 | $this->values['device_info'] = $value; 91 | } 92 | 93 | /** 94 | * 获取终端设备号(商户自定义,如门店编号)的值 95 | * @return 值 96 | **/ 97 | public function getDeviceInfo() 98 | { 99 | return $this->values['device_info']; 100 | } 101 | 102 | /** 103 | * 判断终端设备号(商户自定义,如门店编号)是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isDeviceInfoSet() 107 | { 108 | return array_key_exists('device_info', $this->values); 109 | } 110 | 111 | /** 112 | * 设置随机字符串,不长于32位。推荐随机数生成算法 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | 138 | /** 139 | * 设置商品或支付单简要描述 140 | * @param string $value 141 | **/ 142 | public function setBody($value) 143 | { 144 | $this->values['body'] = $value; 145 | } 146 | 147 | /** 148 | * 获取商品或支付单简要描述的值 149 | * @return 值 150 | **/ 151 | public function getBody() 152 | { 153 | return $this->values['body']; 154 | } 155 | 156 | /** 157 | * 判断商品或支付单简要描述是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isBodySet() 161 | { 162 | return array_key_exists('body', $this->values); 163 | } 164 | 165 | /** 166 | * 设置商品名称明细列表 167 | * @param string $value 168 | **/ 169 | public function setDetail($value) 170 | { 171 | $this->values['detail'] = $value; 172 | } 173 | 174 | /** 175 | * 获取商品名称明细列表的值 176 | * @return 值 177 | **/ 178 | public function getDetail() 179 | { 180 | return $this->values['detail']; 181 | } 182 | 183 | /** 184 | * 判断商品名称明细列表是否存在 185 | * @return true 或 false 186 | **/ 187 | public function isDetailSet() 188 | { 189 | return array_key_exists('detail', $this->values); 190 | } 191 | 192 | /** 193 | * 设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据 194 | * @param string $value 195 | **/ 196 | public function setAttach($value) 197 | { 198 | $this->values['attach'] = $value; 199 | } 200 | 201 | /** 202 | * 获取附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据的值 203 | * @return 值 204 | **/ 205 | public function getAttach() 206 | { 207 | return $this->values['attach']; 208 | } 209 | 210 | /** 211 | * 判断附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据是否存在 212 | * @return true 或 false 213 | **/ 214 | public function isAttachSet() 215 | { 216 | return array_key_exists('attach', $this->values); 217 | } 218 | 219 | /** 220 | * 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号 221 | * @param string $value 222 | **/ 223 | public function setOutTradeNo($value) 224 | { 225 | $this->values['out_trade_no'] = $value; 226 | } 227 | 228 | /** 229 | * 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值 230 | * @return 值 231 | **/ 232 | public function getOutTradeNo() 233 | { 234 | return $this->values['out_trade_no']; 235 | } 236 | 237 | /** 238 | * 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在 239 | * @return true 或 false 240 | **/ 241 | public function isOutTradeNoSet() 242 | { 243 | return array_key_exists('out_trade_no', $this->values); 244 | } 245 | 246 | /** 247 | * 设置订单总金额,单位为分,只能为整数,详见支付金额 248 | * @param string $value 249 | **/ 250 | public function setTotalFee($value) 251 | { 252 | $this->values['total_fee'] = $value; 253 | } 254 | 255 | /** 256 | * 获取订单总金额,单位为分,只能为整数,详见支付金额的值 257 | * @return 值 258 | **/ 259 | public function getTotalFee() 260 | { 261 | return $this->values['total_fee']; 262 | } 263 | 264 | /** 265 | * 判断订单总金额,单位为分,只能为整数,详见支付金额是否存在 266 | * @return true 或 false 267 | **/ 268 | public function isTotalFeeSet() 269 | { 270 | return array_key_exists('total_fee', $this->values); 271 | } 272 | 273 | /** 274 | * 设置符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 275 | * @param string $value 276 | **/ 277 | public function setFeeType($value) 278 | { 279 | $this->values['fee_type'] = $value; 280 | } 281 | 282 | /** 283 | * 获取符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值 284 | * @return 值 285 | **/ 286 | public function getFeeType() 287 | { 288 | return $this->values['fee_type']; 289 | } 290 | 291 | /** 292 | * 判断符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在 293 | * @return true 或 false 294 | **/ 295 | public function isFeeTypeSet() 296 | { 297 | return array_key_exists('fee_type', $this->values); 298 | } 299 | 300 | /** 301 | * 设置调用微信支付API的机器IP 302 | * @param string $value 303 | **/ 304 | public function setSpbillCreateIp($value) 305 | { 306 | $this->values['spbill_create_ip'] = $value; 307 | } 308 | 309 | /** 310 | * 获取调用微信支付API的机器IP 的值 311 | * @return 值 312 | **/ 313 | public function getSpbillCreateIp() 314 | { 315 | return $this->values['spbill_create_ip']; 316 | } 317 | 318 | /** 319 | * 判断调用微信支付API的机器IP 是否存在 320 | * @return true 或 false 321 | **/ 322 | public function isSpbillCreateIpSet() 323 | { 324 | return array_key_exists('spbill_create_ip', $this->values); 325 | } 326 | 327 | /** 328 | * 设置订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则 329 | * @param string $value 330 | **/ 331 | public function setTimeStart($value) 332 | { 333 | $this->values['time_start'] = $value; 334 | } 335 | 336 | /** 337 | * 获取订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则的值 338 | * @return 值 339 | **/ 340 | public function getTimeStart() 341 | { 342 | return $this->values['time_start']; 343 | } 344 | 345 | /** 346 | * 判断订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则是否存在 347 | * @return true 或 false 348 | **/ 349 | public function isTimeStartSet() 350 | { 351 | return array_key_exists('time_start', $this->values); 352 | } 353 | 354 | /** 355 | * 设置订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则 356 | * @param string $value 357 | **/ 358 | public function setTimeExpire($value) 359 | { 360 | $this->values['time_expire'] = $value; 361 | } 362 | 363 | /** 364 | * 获取订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则的值 365 | * @return 值 366 | **/ 367 | public function getTimeExpire() 368 | { 369 | return $this->values['time_expire']; 370 | } 371 | 372 | /** 373 | * 判断订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则是否存在 374 | * @return true 或 false 375 | **/ 376 | public function isTimeExpireSet() 377 | { 378 | return array_key_exists('time_expire', $this->values); 379 | } 380 | 381 | /** 382 | * 设置商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠 383 | * @param string $value 384 | **/ 385 | public function setGoodsTag($value) 386 | { 387 | $this->values['goods_tag'] = $value; 388 | } 389 | 390 | /** 391 | * 获取商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠的值 392 | * @return 值 393 | **/ 394 | public function getGoodsTag() 395 | { 396 | return $this->values['goods_tag']; 397 | } 398 | 399 | /** 400 | * 判断商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠是否存在 401 | * @return true 或 false 402 | **/ 403 | public function isGoodsTagSet() 404 | { 405 | return array_key_exists('goods_tag', $this->values); 406 | } 407 | 408 | /** 409 | * 设置扫码支付授权码,设备读取用户微信中的条码或者二维码信息 410 | * @param string $value 411 | **/ 412 | public function setAuthCode($value) 413 | { 414 | $this->values['auth_code'] = $value; 415 | } 416 | 417 | /** 418 | * 获取扫码支付授权码,设备读取用户微信中的条码或者二维码信息的值 419 | * @return 值 420 | **/ 421 | public function getAuthCode() 422 | { 423 | return $this->values['auth_code']; 424 | } 425 | 426 | /** 427 | * 判断扫码支付授权码,设备读取用户微信中的条码或者二维码信息是否存在 428 | * @return true 或 false 429 | **/ 430 | public function isAuthCodeSet() 431 | { 432 | return array_key_exists('auth_code', $this->values); 433 | } 434 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/NotifyReply.php: -------------------------------------------------------------------------------- 1 | values['return_code'] = $return_code; 20 | } 21 | 22 | /** 23 | * 24 | * 获取错误码 FAIL 或者 SUCCESS 25 | * @return string $return_code 26 | */ 27 | public function getReturnCode() 28 | { 29 | return $this->values['return_code']; 30 | } 31 | 32 | /** 33 | * 34 | * 设置错误信息 35 | * @param string $return_code 36 | */ 37 | public function setReturnMsg($return_msg) 38 | { 39 | $this->values['return_msg'] = $return_msg; 40 | } 41 | 42 | /** 43 | * 44 | * 获取错误信息 45 | * @return string 46 | */ 47 | public function getReturnMsg() 48 | { 49 | return $this->values['return_msg']; 50 | } 51 | 52 | /** 53 | * 54 | * 设置返回参数 55 | * @param string $key 56 | * @param string $value 57 | */ 58 | public function setData($key, $value) 59 | { 60 | $this->values[$key] = $value; 61 | } 62 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/OrderQuery.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置微信的订单号,优先使用 86 | * @param string $value 87 | **/ 88 | public function setTransactionId($value) 89 | { 90 | $this->values['transaction_id'] = $value; 91 | } 92 | 93 | /** 94 | * 获取微信的订单号,优先使用的值 95 | * @return 值 96 | **/ 97 | public function getTransactionId() 98 | { 99 | return $this->values['transaction_id']; 100 | } 101 | 102 | /** 103 | * 判断微信的订单号,优先使用是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isTransactionIdSet() 107 | { 108 | return array_key_exists('transaction_id', $this->values); 109 | } 110 | 111 | /** 112 | * 设置商户系统内部的订单号,当没提供transaction_id时需要传这个。 113 | * @param string $value 114 | **/ 115 | public function setOutTradeNo($value) 116 | { 117 | $this->values['out_trade_no'] = $value; 118 | } 119 | 120 | /** 121 | * 获取商户系统内部的订单号,当没提供transaction_id时需要传这个。的值 122 | * @return 值 123 | **/ 124 | public function getOutTradeNo() 125 | { 126 | return $this->values['out_trade_no']; 127 | } 128 | 129 | /** 130 | * 判断商户系统内部的订单号,当没提供transaction_id时需要传这个。是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isOutTradeNoSet() 134 | { 135 | return array_key_exists('out_trade_no', $this->values); 136 | } 137 | 138 | /** 139 | * 设置随机字符串,不长于32位。推荐随机数生成算法 140 | * @param string $value 141 | **/ 142 | public function setNonceStr($value) 143 | { 144 | $this->values['nonce_str'] = $value; 145 | } 146 | 147 | /** 148 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 149 | * @return 值 150 | **/ 151 | public function getNonceStr() 152 | { 153 | return $this->values['nonce_str']; 154 | } 155 | 156 | /** 157 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isNonceStrSet() 161 | { 162 | return array_key_exists('nonce_str', $this->values); 163 | } 164 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/Refund.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置微信支付分配的终端设备号,与下单一致 86 | * @param string $value 87 | **/ 88 | public function setDeviceInfo($value) 89 | { 90 | $this->values['device_info'] = $value; 91 | } 92 | 93 | /** 94 | * 获取微信支付分配的终端设备号,与下单一致的值 95 | * @return 值 96 | **/ 97 | public function getDeviceInfo() 98 | { 99 | return $this->values['device_info']; 100 | } 101 | 102 | /** 103 | * 判断微信支付分配的终端设备号,与下单一致是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isDeviceInfoSet() 107 | { 108 | return array_key_exists('device_info', $this->values); 109 | } 110 | 111 | /** 112 | * 设置随机字符串,不长于32位。推荐随机数生成算法 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | 138 | /** 139 | * 设置微信订单号 140 | * @param string $value 141 | **/ 142 | public function setTransactionId($value) 143 | { 144 | $this->values['transaction_id'] = $value; 145 | } 146 | 147 | /** 148 | * 获取微信订单号的值 149 | * @return 值 150 | **/ 151 | public function getTransactionId() 152 | { 153 | return $this->values['transaction_id']; 154 | } 155 | 156 | /** 157 | * 判断微信订单号是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isTransactionIdSet() 161 | { 162 | return array_key_exists('transaction_id', $this->values); 163 | } 164 | 165 | /** 166 | * 设置商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no 167 | * @param string $value 168 | **/ 169 | public function setOutTradeNo($value) 170 | { 171 | $this->values['out_trade_no'] = $value; 172 | } 173 | 174 | /** 175 | * 获取商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no的值 176 | * @return 值 177 | **/ 178 | public function getOutTradeNo() 179 | { 180 | return $this->values['out_trade_no']; 181 | } 182 | 183 | /** 184 | * 判断商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no是否存在 185 | * @return true 或 false 186 | **/ 187 | public function isOutTradeNoSet() 188 | { 189 | return array_key_exists('out_trade_no', $this->values); 190 | } 191 | 192 | /** 193 | * 设置商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔 194 | * @param string $value 195 | **/ 196 | public function setOutRefundNo($value) 197 | { 198 | $this->values['out_refund_no'] = $value; 199 | } 200 | 201 | /** 202 | * 获取商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔的值 203 | * @return 值 204 | **/ 205 | public function getOutRefundNo() 206 | { 207 | return $this->values['out_refund_no']; 208 | } 209 | 210 | /** 211 | * 判断商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔是否存在 212 | * @return true 或 false 213 | **/ 214 | public function isOutRefundNoSet() 215 | { 216 | return array_key_exists('out_refund_no', $this->values); 217 | } 218 | 219 | /** 220 | * 设置订单总金额,单位为分,只能为整数,详见支付金额 221 | * @param string $value 222 | **/ 223 | public function setTotalFee($value) 224 | { 225 | $this->values['total_fee'] = $value; 226 | } 227 | 228 | /** 229 | * 获取订单总金额,单位为分,只能为整数,详见支付金额的值 230 | * @return 值 231 | **/ 232 | public function getTotalFee() 233 | { 234 | return $this->values['total_fee']; 235 | } 236 | 237 | /** 238 | * 判断订单总金额,单位为分,只能为整数,详见支付金额是否存在 239 | * @return true 或 false 240 | **/ 241 | public function isTotalFeeSet() 242 | { 243 | return array_key_exists('total_fee', $this->values); 244 | } 245 | 246 | /** 247 | * 设置退款总金额,订单总金额,单位为分,只能为整数,详见支付金额 248 | * @param string $value 249 | **/ 250 | public function setRefundFee($value) 251 | { 252 | $this->values['refund_fee'] = $value; 253 | } 254 | 255 | /** 256 | * 获取退款总金额,订单总金额,单位为分,只能为整数,详见支付金额的值 257 | * @return 值 258 | **/ 259 | public function getRefundFee() 260 | { 261 | return $this->values['refund_fee']; 262 | } 263 | 264 | /** 265 | * 判断退款总金额,订单总金额,单位为分,只能为整数,详见支付金额是否存在 266 | * @return true 或 false 267 | **/ 268 | public function isRefundFeeSet() 269 | { 270 | return array_key_exists('refund_fee', $this->values); 271 | } 272 | 273 | /** 274 | * 设置货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 275 | * @param string $value 276 | **/ 277 | public function setRefundFeeType($value) 278 | { 279 | $this->values['refund_fee_type'] = $value; 280 | } 281 | 282 | /** 283 | * 获取货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值 284 | * @return 值 285 | **/ 286 | public function getRefundFeeType() 287 | { 288 | return $this->values['refund_fee_type']; 289 | } 290 | 291 | /** 292 | * 判断货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在 293 | * @return true 或 false 294 | **/ 295 | public function isRefundFeeTypeSet() 296 | { 297 | return array_key_exists('refund_fee_type', $this->values); 298 | } 299 | 300 | /** 301 | * 设置操作员帐号, 默认为商户号 302 | * @param string $value 303 | **/ 304 | public function setOpUserId($value) 305 | { 306 | $this->values['op_user_id'] = $value; 307 | } 308 | 309 | /** 310 | * 获取操作员帐号, 默认为商户号的值 311 | * @return 值 312 | **/ 313 | public function getOpUserId() 314 | { 315 | return $this->values['op_user_id']; 316 | } 317 | 318 | /** 319 | * 判断操作员帐号, 默认为商户号是否存在 320 | * @return true 或 false 321 | **/ 322 | public function isOpUserIdSet() 323 | { 324 | return array_key_exists('op_user_id', $this->values); 325 | } 326 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/RefundQuery.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置微信支付分配的终端设备号 86 | * @param string $value 87 | **/ 88 | public function setDeviceInfo($value) 89 | { 90 | $this->values['device_info'] = $value; 91 | } 92 | 93 | /** 94 | * 获取微信支付分配的终端设备号的值 95 | * @return 值 96 | **/ 97 | public function getDeviceInfo() 98 | { 99 | return $this->values['device_info']; 100 | } 101 | 102 | /** 103 | * 判断微信支付分配的终端设备号是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isDeviceInfoSet() 107 | { 108 | return array_key_exists('device_info', $this->values); 109 | } 110 | 111 | /** 112 | * 设置随机字符串,不长于32位。推荐随机数生成算法 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | 138 | /** 139 | * 设置微信订单号 140 | * @param string $value 141 | **/ 142 | public function setTransactionId($value) 143 | { 144 | $this->values['transaction_id'] = $value; 145 | } 146 | 147 | /** 148 | * 获取微信订单号的值 149 | * @return 值 150 | **/ 151 | public function getTransactionId() 152 | { 153 | return $this->values['transaction_id']; 154 | } 155 | 156 | /** 157 | * 判断微信订单号是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isTransactionIdSet() 161 | { 162 | return array_key_exists('transaction_id', $this->values); 163 | } 164 | 165 | /** 166 | * 设置商户系统内部的订单号 167 | * @param string $value 168 | **/ 169 | public function setOutTradeNo($value) 170 | { 171 | $this->values['out_trade_no'] = $value; 172 | } 173 | 174 | /** 175 | * 获取商户系统内部的订单号的值 176 | * @return 值 177 | **/ 178 | public function getOutTradeNo() 179 | { 180 | return $this->values['out_trade_no']; 181 | } 182 | 183 | /** 184 | * 判断商户系统内部的订单号是否存在 185 | * @return true 或 false 186 | **/ 187 | public function isOutTradeNoSet() 188 | { 189 | return array_key_exists('out_trade_no', $this->values); 190 | } 191 | 192 | /** 193 | * 设置商户退款单号 194 | * @param string $value 195 | **/ 196 | public function setOutRefundNo($value) 197 | { 198 | $this->values['out_refund_no'] = $value; 199 | } 200 | 201 | /** 202 | * 获取商户退款单号的值 203 | * @return 值 204 | **/ 205 | public function getOutRefundNo() 206 | { 207 | return $this->values['out_refund_no']; 208 | } 209 | 210 | /** 211 | * 判断商户退款单号是否存在 212 | * @return true 或 false 213 | **/ 214 | public function isOutRefundNoSet() 215 | { 216 | return array_key_exists('out_refund_no', $this->values); 217 | } 218 | 219 | /** 220 | * 设置微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no 221 | * @param string $value 222 | **/ 223 | public function setRefundId($value) 224 | { 225 | $this->values['refund_id'] = $value; 226 | } 227 | 228 | /** 229 | * 获取微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no的值 230 | * @return 值 231 | **/ 232 | public function getRefundId() 233 | { 234 | return $this->values['refund_id']; 235 | } 236 | 237 | /** 238 | * 判断微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no是否存在 239 | * @return true 或 false 240 | **/ 241 | public function isRefundIdSet() 242 | { 243 | return array_key_exists('refund_id', $this->values); 244 | } 245 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/Report.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置微信支付分配的终端设备号,商户自定义 86 | * @param string $value 87 | **/ 88 | public function setDeviceInfo($value) 89 | { 90 | $this->values['device_info'] = $value; 91 | } 92 | 93 | /** 94 | * 获取微信支付分配的终端设备号,商户自定义的值 95 | * @return 值 96 | **/ 97 | public function getDeviceInfo() 98 | { 99 | return $this->values['device_info']; 100 | } 101 | 102 | /** 103 | * 判断微信支付分配的终端设备号,商户自定义是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isDeviceInfoSet() 107 | { 108 | return array_key_exists('device_info', $this->values); 109 | } 110 | 111 | /** 112 | * 设置随机字符串,不长于32位。推荐随机数生成算法 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | 138 | /** 139 | * 设置上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。 140 | * @param string $value 141 | **/ 142 | public function setInterfaceUrl($value) 143 | { 144 | $this->values['interface_url'] = $value; 145 | } 146 | 147 | /** 148 | * 获取上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。的值 149 | * @return 值 150 | **/ 151 | public function getInterfaceUrl() 152 | { 153 | return $this->values['interface_url']; 154 | } 155 | 156 | /** 157 | * 判断上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isInterfaceUrlSet() 161 | { 162 | return array_key_exists('interface_url', $this->values); 163 | } 164 | 165 | /** 166 | * 设置接口耗时情况,单位为毫秒 167 | * @param string $value 168 | **/ 169 | public function setExecuteTime($value) 170 | { 171 | $this->values['execute_time_'] = $value; 172 | } 173 | 174 | /** 175 | * 获取接口耗时情况,单位为毫秒的值 176 | * @return 值 177 | **/ 178 | public function getExecuteTime() 179 | { 180 | return $this->values['execute_time_']; 181 | } 182 | 183 | /** 184 | * 判断接口耗时情况,单位为毫秒是否存在 185 | * @return true 或 false 186 | **/ 187 | public function isExecuteTimeSet() 188 | { 189 | return array_key_exists('execute_time_', $this->values); 190 | } 191 | 192 | /** 193 | * 设置SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断 194 | * @param string $value 195 | **/ 196 | public function setReturnCode($value) 197 | { 198 | $this->values['return_code'] = $value; 199 | } 200 | 201 | /** 202 | * 获取SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断的值 203 | * @return 值 204 | **/ 205 | public function getReturnCode() 206 | { 207 | return $this->values['return_code']; 208 | } 209 | 210 | /** 211 | * 判断SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断是否存在 212 | * @return true 或 false 213 | **/ 214 | public function isReturnCodeSet() 215 | { 216 | return array_key_exists('return_code', $this->values); 217 | } 218 | 219 | /** 220 | * 设置返回信息,如非空,为错误原因签名失败参数格式校验错误 221 | * @param string $value 222 | **/ 223 | public function setReturnMsg($value) 224 | { 225 | $this->values['return_msg'] = $value; 226 | } 227 | 228 | /** 229 | * 获取返回信息,如非空,为错误原因签名失败参数格式校验错误的值 230 | * @return 值 231 | **/ 232 | public function getReturnMsg() 233 | { 234 | return $this->values['return_msg']; 235 | } 236 | 237 | /** 238 | * 判断返回信息,如非空,为错误原因签名失败参数格式校验错误是否存在 239 | * @return true 或 false 240 | **/ 241 | public function isReturnMsgSet() 242 | { 243 | return array_key_exists('return_msg', $this->values); 244 | } 245 | 246 | /** 247 | * 设置SUCCESS/FAIL 248 | * @param string $value 249 | **/ 250 | public function setResultCode($value) 251 | { 252 | $this->values['result_code'] = $value; 253 | } 254 | 255 | /** 256 | * 获取SUCCESS/FAIL的值 257 | * @return 值 258 | **/ 259 | public function getResultCode() 260 | { 261 | return $this->values['result_code']; 262 | } 263 | 264 | /** 265 | * 判断SUCCESS/FAIL是否存在 266 | * @return true 或 false 267 | **/ 268 | public function isResultCodeSet() 269 | { 270 | return array_key_exists('result_code', $this->values); 271 | } 272 | 273 | /** 274 | * 设置ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误 275 | * @param string $value 276 | **/ 277 | public function setErrCode($value) 278 | { 279 | $this->values['err_code'] = $value; 280 | } 281 | 282 | /** 283 | * 获取ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误的值 284 | * @return 值 285 | **/ 286 | public function getErrCode() 287 | { 288 | return $this->values['err_code']; 289 | } 290 | 291 | /** 292 | * 判断ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误是否存在 293 | * @return true 或 false 294 | **/ 295 | public function isErrCodeSet() 296 | { 297 | return array_key_exists('err_code', $this->values); 298 | } 299 | 300 | /** 301 | * 设置结果信息描述 302 | * @param string $value 303 | **/ 304 | public function setErrCodeDes($value) 305 | { 306 | $this->values['err_code_des'] = $value; 307 | } 308 | 309 | /** 310 | * 获取结果信息描述的值 311 | * @return 值 312 | **/ 313 | public function getErrCodeDes() 314 | { 315 | return $this->values['err_code_des']; 316 | } 317 | 318 | /** 319 | * 判断结果信息描述是否存在 320 | * @return true 或 false 321 | **/ 322 | public function isErrCodeDesSet() 323 | { 324 | return array_key_exists('err_code_des', $this->values); 325 | } 326 | 327 | /** 328 | * 设置商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 329 | * @param string $value 330 | **/ 331 | public function setOutTradeNo($value) 332 | { 333 | $this->values['out_trade_no'] = $value; 334 | } 335 | 336 | /** 337 | * 获取商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 的值 338 | * @return 值 339 | **/ 340 | public function getOutTradeNo() 341 | { 342 | return $this->values['out_trade_no']; 343 | } 344 | 345 | /** 346 | * 判断商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 是否存在 347 | * @return true 或 false 348 | **/ 349 | public function isOutTradeNoSet() 350 | { 351 | return array_key_exists('out_trade_no', $this->values); 352 | } 353 | 354 | /** 355 | * 设置发起接口调用时的机器IP 356 | * @param string $value 357 | **/ 358 | public function setUserIp($value) 359 | { 360 | $this->values['user_ip'] = $value; 361 | } 362 | 363 | /** 364 | * 获取发起接口调用时的机器IP 的值 365 | * @return 值 366 | **/ 367 | public function getUserIp() 368 | { 369 | return $this->values['user_ip']; 370 | } 371 | 372 | /** 373 | * 判断发起接口调用时的机器IP 是否存在 374 | * @return true 或 false 375 | **/ 376 | public function isUserIpSet() 377 | { 378 | return array_key_exists('user_ip', $this->values); 379 | } 380 | 381 | /** 382 | * 设置系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则 383 | * @param string $value 384 | **/ 385 | public function setTime($value) 386 | { 387 | $this->values['time'] = $value; 388 | } 389 | 390 | /** 391 | * 获取系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则的值 392 | * @return 值 393 | **/ 394 | public function getTime() 395 | { 396 | return $this->values['time']; 397 | } 398 | 399 | /** 400 | * 判断系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则是否存在 401 | * @return true 或 false 402 | **/ 403 | public function isTimeSet() 404 | { 405 | return array_key_exists('time', $this->values); 406 | } 407 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/Results.php: -------------------------------------------------------------------------------- 1 | isSignSet()) { 22 | throw new WxPayException('签名错误!'); 23 | } 24 | 25 | $sign = $this->makeSign(); 26 | if ($this->getSign() == $sign) { 27 | return true; 28 | } 29 | throw new WxPayException('签名错误!'); 30 | } 31 | 32 | /** 33 | * 34 | * 使用数组初始化 35 | * @param array $array 36 | */ 37 | public function FromArray($array) 38 | { 39 | $this->values = $array; 40 | } 41 | 42 | /** 43 | * 44 | * 使用数组初始化对象 45 | * @param array $array 46 | * @param 是否检测签名 $noCheckSign 47 | */ 48 | public static function InitFromArray($array, $noCheckSign = false) 49 | { 50 | $obj = new self(); 51 | $obj->FromArray($array); 52 | if ($noCheckSign == false) { 53 | $obj->CheckSign(); 54 | } 55 | return $obj; 56 | } 57 | 58 | /** 59 | * 60 | * 设置参数 61 | * @param string $key 62 | * @param string $value 63 | */ 64 | public function setData($key, $value) 65 | { 66 | $this->values[$key] = $value; 67 | } 68 | 69 | /** 70 | * 将xml转为array 71 | * @param string $xml 72 | * @throws WxPayException 73 | */ 74 | public static function Init($xml) 75 | { 76 | $obj = new self(); 77 | $obj->fromXml($xml); 78 | //fix bug 2015-06-29 79 | if ($obj->values['return_code'] != 'SUCCESS') { 80 | return $obj->getValues(); 81 | } 82 | $obj->CheckSign(); 83 | return $obj->getValues(); 84 | } 85 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/Reverse.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置微信的订单号,优先使用 86 | * @param string $value 87 | **/ 88 | public function setTransactionId($value) 89 | { 90 | $this->values['transaction_id'] = $value; 91 | } 92 | 93 | /** 94 | * 获取微信的订单号,优先使用的值 95 | * @return 值 96 | **/ 97 | public function getTransactionId() 98 | { 99 | return $this->values['transaction_id']; 100 | } 101 | 102 | /** 103 | * 判断微信的订单号,优先使用是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isTransactionIdSet() 107 | { 108 | return array_key_exists('transaction_id', $this->values); 109 | } 110 | 111 | /** 112 | * 设置商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no 113 | * @param string $value 114 | **/ 115 | public function setOutTradeNo($value) 116 | { 117 | $this->values['out_trade_no'] = $value; 118 | } 119 | 120 | /** 121 | * 获取商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no的值 122 | * @return 值 123 | **/ 124 | public function getOutTradeNo() 125 | { 126 | return $this->values['out_trade_no']; 127 | } 128 | 129 | /** 130 | * 判断商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isOutTradeNoSet() 134 | { 135 | return array_key_exists('out_trade_no', $this->values); 136 | } 137 | 138 | /** 139 | * 设置随机字符串,不长于32位。推荐随机数生成算法 140 | * @param string $value 141 | **/ 142 | public function setNonceStr($value) 143 | { 144 | $this->values['nonce_str'] = $value; 145 | } 146 | 147 | /** 148 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 149 | * @return 值 150 | **/ 151 | public function getNonceStr() 152 | { 153 | return $this->values['nonce_str']; 154 | } 155 | 156 | /** 157 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isNonceStrSet() 161 | { 162 | return array_key_exists('nonce_str', $this->values); 163 | } 164 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/ShortUrl.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置需要转换的URL,签名用原串,传输需URL encode 86 | * @param string $value 87 | **/ 88 | public function setLongUrl($value) 89 | { 90 | $this->values['long_url'] = $value; 91 | } 92 | 93 | /** 94 | * 获取需要转换的URL,签名用原串,传输需URL encode的值 95 | * @return 值 96 | **/ 97 | public function getLongUrl() 98 | { 99 | return $this->values['long_url']; 100 | } 101 | 102 | /** 103 | * 判断需要转换的URL,签名用原串,传输需URL encode是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isLongUrlSet() 107 | { 108 | return array_key_exists('long_url', $this->values); 109 | } 110 | 111 | /** 112 | * 设置随机字符串,不长于32位。推荐随机数生成算法 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Models/UnifiedOrder.php: -------------------------------------------------------------------------------- 1 | values['appid'] = $value; 19 | } 20 | 21 | /** 22 | * 获取微信分配的公众账号ID的值 23 | * @return 值 24 | **/ 25 | public function getAppid() 26 | { 27 | return $this->values['appid']; 28 | } 29 | 30 | /** 31 | * 判断微信分配的公众账号ID是否存在 32 | * @return true 或 false 33 | **/ 34 | public function isAppidSet() 35 | { 36 | return array_key_exists('appid', $this->values); 37 | } 38 | 39 | /** 40 | * 设置微信支付分配的商户号 41 | * @param string $value 42 | **/ 43 | public function setMchId($value) 44 | { 45 | $this->values['mch_id'] = $value; 46 | } 47 | 48 | /** 49 | * 获取微信支付分配的商户号的值 50 | * @return 值 51 | **/ 52 | public function getMchId() 53 | { 54 | return $this->values['mch_id']; 55 | } 56 | 57 | /** 58 | * 判断微信支付分配的商户号是否存在 59 | * @return true 或 false 60 | **/ 61 | public function isMchIdSet() 62 | { 63 | return array_key_exists('mch_id', $this->values); 64 | } 65 | 66 | /** 67 | * 设置子商户的商户号 68 | * @param string $value 69 | **/ 70 | public function setSubMchId($value) 71 | { 72 | $this->values['sub_mch_id'] = $value; 73 | } 74 | 75 | /** 76 | * 获取子商户号的值 77 | * @return 值 78 | **/ 79 | public function getSubMchId() 80 | { 81 | return $this->values['sub_mch_id']; 82 | } 83 | 84 | /** 85 | * 设置微信支付分配的终端设备号,商户自定义 86 | * @param string $value 87 | **/ 88 | public function setDeviceInfo($value) 89 | { 90 | $this->values['device_info'] = $value; 91 | } 92 | 93 | /** 94 | * 获取微信支付分配的终端设备号,商户自定义的值 95 | * @return 值 96 | **/ 97 | public function getDeviceInfo() 98 | { 99 | return $this->values['device_info']; 100 | } 101 | 102 | /** 103 | * 判断微信支付分配的终端设备号,商户自定义是否存在 104 | * @return true 或 false 105 | **/ 106 | public function isDeviceInfoSet() 107 | { 108 | return array_key_exists('device_info', $this->values); 109 | } 110 | 111 | /** 112 | * 设置随机字符串,不长于32位。推荐随机数生成算法 113 | * @param string $value 114 | **/ 115 | public function setNonceStr($value) 116 | { 117 | $this->values['nonce_str'] = $value; 118 | } 119 | 120 | /** 121 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值 122 | * @return 值 123 | **/ 124 | public function getNonceStr() 125 | { 126 | return $this->values['nonce_str']; 127 | } 128 | 129 | /** 130 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在 131 | * @return true 或 false 132 | **/ 133 | public function isNonceStrSet() 134 | { 135 | return array_key_exists('nonce_str', $this->values); 136 | } 137 | 138 | /** 139 | * 设置商品或支付单简要描述 140 | * @param string $value 141 | **/ 142 | public function setBody($value) 143 | { 144 | $this->values['body'] = $value; 145 | } 146 | 147 | /** 148 | * 获取商品或支付单简要描述的值 149 | * @return 值 150 | **/ 151 | public function getBody() 152 | { 153 | return $this->values['body']; 154 | } 155 | 156 | /** 157 | * 判断商品或支付单简要描述是否存在 158 | * @return true 或 false 159 | **/ 160 | public function isBodySet() 161 | { 162 | return array_key_exists('body', $this->values); 163 | } 164 | 165 | /** 166 | * 设置商品名称明细列表 167 | * @param string $value 168 | **/ 169 | public function setDetail($value) 170 | { 171 | $this->values['detail'] = $value; 172 | } 173 | 174 | /** 175 | * 获取商品名称明细列表的值 176 | * @return 值 177 | **/ 178 | public function getDetail() 179 | { 180 | return $this->values['detail']; 181 | } 182 | 183 | /** 184 | * 判断商品名称明细列表是否存在 185 | * @return true 或 false 186 | **/ 187 | public function isDetailSet() 188 | { 189 | return array_key_exists('detail', $this->values); 190 | } 191 | 192 | /** 193 | * 设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据 194 | * @param string $value 195 | **/ 196 | public function setAttach($value) 197 | { 198 | $this->values['attach'] = $value; 199 | } 200 | 201 | /** 202 | * 获取附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据的值 203 | * @return 值 204 | **/ 205 | public function getAttach() 206 | { 207 | return $this->values['attach']; 208 | } 209 | 210 | /** 211 | * 判断附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据是否存在 212 | * @return true 或 false 213 | **/ 214 | public function isAttachSet() 215 | { 216 | return array_key_exists('attach', $this->values); 217 | } 218 | 219 | /** 220 | * 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号 221 | * @param string $value 222 | **/ 223 | public function setOutTradeNo($value) 224 | { 225 | $this->values['out_trade_no'] = $value; 226 | } 227 | 228 | /** 229 | * 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值 230 | * @return 值 231 | **/ 232 | public function getOutTradeNo() 233 | { 234 | return $this->values['out_trade_no']; 235 | } 236 | 237 | /** 238 | * 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在 239 | * @return true 或 false 240 | **/ 241 | public function isOutTradeNoSet() 242 | { 243 | return array_key_exists('out_trade_no', $this->values); 244 | } 245 | 246 | /** 247 | * 设置符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 248 | * @param string $value 249 | **/ 250 | public function setFeeType($value) 251 | { 252 | $this->values['fee_type'] = $value; 253 | } 254 | 255 | /** 256 | * 获取符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值 257 | * @return 值 258 | **/ 259 | public function getFeeType() 260 | { 261 | return $this->values['fee_type']; 262 | } 263 | 264 | /** 265 | * 判断符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在 266 | * @return true 或 false 267 | **/ 268 | public function isFeeTypeSet() 269 | { 270 | return array_key_exists('fee_type', $this->values); 271 | } 272 | 273 | /** 274 | * 设置订单总金额,只能为整数,详见支付金额 275 | * @param string $value 276 | **/ 277 | public function setTotalFee($value) 278 | { 279 | $this->values['total_fee'] = $value; 280 | } 281 | 282 | /** 283 | * 获取订单总金额,只能为整数,详见支付金额的值 284 | * @return 值 285 | **/ 286 | public function getTotalFee() 287 | { 288 | return $this->values['total_fee']; 289 | } 290 | 291 | /** 292 | * 判断订单总金额,只能为整数,详见支付金额是否存在 293 | * @return true 或 false 294 | **/ 295 | public function isTotalFeeSet() 296 | { 297 | return array_key_exists('total_fee', $this->values); 298 | } 299 | 300 | /** 301 | * 设置APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。 302 | * @param string $value 303 | **/ 304 | public function setSpbillCreateIp($value) 305 | { 306 | $this->values['spbill_create_ip'] = $value; 307 | } 308 | 309 | /** 310 | * 获取APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。的值 311 | * @return 值 312 | **/ 313 | public function getSpbillCreateIp() 314 | { 315 | return $this->values['spbill_create_ip']; 316 | } 317 | 318 | /** 319 | * 判断APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。是否存在 320 | * @return true 或 false 321 | **/ 322 | public function isSpbillCreateIpSet() 323 | { 324 | return array_key_exists('spbill_create_ip', $this->values); 325 | } 326 | 327 | /** 328 | * 设置订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则 329 | * @param string $value 330 | **/ 331 | public function setTimeStart($value) 332 | { 333 | $this->values['time_start'] = $value; 334 | } 335 | 336 | /** 337 | * 获取订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则的值 338 | * @return 值 339 | **/ 340 | public function getTimeStart() 341 | { 342 | return $this->values['time_start']; 343 | } 344 | 345 | /** 346 | * 判断订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则是否存在 347 | * @return true 或 false 348 | **/ 349 | public function isTimeStartSet() 350 | { 351 | return array_key_exists('time_start', $this->values); 352 | } 353 | 354 | /** 355 | * 设置订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则 356 | * @param string $value 357 | **/ 358 | public function setTimeExpire($value) 359 | { 360 | $this->values['time_expire'] = $value; 361 | } 362 | 363 | /** 364 | * 获取订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则的值 365 | * @return 值 366 | **/ 367 | public function getTimeExpire() 368 | { 369 | return $this->values['time_expire']; 370 | } 371 | 372 | /** 373 | * 判断订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则是否存在 374 | * @return true 或 false 375 | **/ 376 | public function isTimeExpireSet() 377 | { 378 | return array_key_exists('time_expire', $this->values); 379 | } 380 | 381 | /** 382 | * 设置商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠 383 | * @param string $value 384 | **/ 385 | public function setGoodsTag($value) 386 | { 387 | $this->values['goods_tag'] = $value; 388 | } 389 | 390 | /** 391 | * 获取商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠的值 392 | * @return 值 393 | **/ 394 | public function getGoodsTag() 395 | { 396 | return $this->values['goods_tag']; 397 | } 398 | 399 | /** 400 | * 判断商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠是否存在 401 | * @return true 或 false 402 | **/ 403 | public function isGoodsTagSet() 404 | { 405 | return array_key_exists('goods_tag', $this->values); 406 | } 407 | 408 | /** 409 | * 设置接收微信支付异步通知回调地址 410 | * @param string $value 411 | **/ 412 | public function setNotifyUrl($value) 413 | { 414 | $this->values['notify_url'] = $value; 415 | } 416 | 417 | /** 418 | * 获取接收微信支付异步通知回调地址的值 419 | * @return 值 420 | **/ 421 | public function getNotifyUrl() 422 | { 423 | return $this->values['notify_url']; 424 | } 425 | 426 | /** 427 | * 判断接收微信支付异步通知回调地址是否存在 428 | * @return true 或 false 429 | **/ 430 | public function isNotifyUrlSet() 431 | { 432 | return array_key_exists('notify_url', $this->values); 433 | } 434 | 435 | /** 436 | * 设置取值如下:JSAPI,NATIVE,APP,详细说明见参数规定 437 | * @param string $value 438 | **/ 439 | public function setTradeType($value) 440 | { 441 | $this->values['trade_type'] = $value; 442 | } 443 | 444 | /** 445 | * 获取取值如下:JSAPI,NATIVE,APP,详细说明见参数规定的值 446 | * @return 值 447 | **/ 448 | public function getTradeType() 449 | { 450 | return $this->values['trade_type']; 451 | } 452 | 453 | /** 454 | * 判断取值如下:JSAPI,NATIVE,APP,详细说明见参数规定是否存在 455 | * @return true 或 false 456 | **/ 457 | public function isTradeTypeSet() 458 | { 459 | return array_key_exists('trade_type', $this->values); 460 | } 461 | 462 | /** 463 | * 设置trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。 464 | * @param string $value 465 | **/ 466 | public function setProductId($value) 467 | { 468 | $this->values['product_id'] = $value; 469 | } 470 | 471 | /** 472 | * 获取trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。的值 473 | * @return 值 474 | **/ 475 | public function getProductId() 476 | { 477 | return $this->values['product_id']; 478 | } 479 | 480 | /** 481 | * 判断trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。是否存在 482 | * @return true 或 false 483 | **/ 484 | public function isProductIdSet() 485 | { 486 | return array_key_exists('product_id', $this->values); 487 | } 488 | 489 | /** 490 | * 设置trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。 491 | * @param string $value 492 | **/ 493 | public function setOpenid($value) 494 | { 495 | $this->values['openid'] = $value; 496 | } 497 | 498 | /** 499 | * 获取trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。 的值 500 | * @return 值 501 | **/ 502 | public function getOpenid() 503 | { 504 | return $this->values['openid']; 505 | } 506 | 507 | /** 508 | * 判断trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。 是否存在 509 | * @return true 或 false 510 | **/ 511 | public function isOpenidSet() 512 | { 513 | return array_key_exists('openid', $this->values); 514 | } 515 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Pay/JsApi.php: -------------------------------------------------------------------------------- 1 | config = $config; 26 | $this->api = new Api($config); 27 | } 28 | 29 | /** 30 | * 31 | * 网页授权接口微信服务器返回的数据,返回样例如下 32 | * { 33 | * 'access_token':'ACCESS_TOKEN', 34 | * 'expires_in':7200, 35 | * 'refresh_token':'REFRESH_TOKEN', 36 | * 'openid':'OPENID', 37 | * 'scope':'SCOPE', 38 | * 'unionid': 'o6_bmasdasdsad6_2sgVt7hMZOPfL' 39 | * } 40 | * 其中access_token可用于获取共享收货地址 41 | * openid是微信支付jsapi支付接口必须的参数 42 | * @var array 43 | */ 44 | public $data = null; 45 | 46 | /** 47 | * 48 | * 通过跳转获取用户的openid,跳转流程如下: 49 | * 1、设置自己需要调回的url及其其他参数,跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize 50 | * 2、微信服务处理完成之后会跳转回用户redirect_uri地址,此时会带上一些参数,如:code 51 | * 52 | * @return 用户的openid 53 | */ 54 | public function GetOpenid() 55 | { 56 | //通过code获得openid 57 | if (! isset($_GET['code'])) { 58 | //触发微信返回code码 59 | $baseUrl = urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $_SERVER['QUERY_STRING']); 60 | $url = $this->__CreateOauthUrlForCode($baseUrl); 61 | Header('Location: ' . $url); 62 | exit(); 63 | } else { 64 | //获取code码,以获取openid 65 | $code = $_GET['code']; 66 | $openid = $this->getOpenidFromMp($code); 67 | return $openid; 68 | } 69 | } 70 | 71 | /** 72 | * 73 | * 获取jsapi支付的参数 74 | * @param array $UnifiedOrderResult 统一支付接口返回的数据 75 | * @throws WxPayException 76 | * 77 | * @return json数据,可直接填入js函数作为参数 78 | */ 79 | public function GetJsApiParameters($UnifiedOrderResult) 80 | { 81 | if (! array_key_exists('appid', $UnifiedOrderResult) || ! array_key_exists('prepay_id', $UnifiedOrderResult) || $UnifiedOrderResult['prepay_id'] == '') { 82 | throw new WxPayException('参数错误'); 83 | } 84 | $jsapi = new WxPayJsApiPay(); 85 | $jsapi->setAppid($UnifiedOrderResult['appid']); 86 | $timeStamp = time(); 87 | $jsapi->setTimeStamp($timeStamp); 88 | $jsapi->setNonceStr($this->api->getNonceStr()); 89 | $jsapi->setPackage('prepay_id=' . $UnifiedOrderResult['prepay_id']); 90 | $jsapi->setSignType('MD5'); 91 | $jsapi->setPaySign($jsapi->makeSign()); 92 | $parameters = json_encode($jsapi->getValues()); 93 | return $parameters; 94 | } 95 | 96 | /** 97 | * 98 | * 通过code从工作平台获取openid机器access_token 99 | * @param string $code 微信跳转回来带上的code 100 | * 101 | * @return openid 102 | */ 103 | public function GetOpenidFromMp($code) 104 | { 105 | $url = $this->__CreateOauthUrlForOpenid($code); 106 | //初始化curl 107 | $ch = curl_init(); 108 | //设置超时 109 | curl_setopt($ch, CURLOP_TIMEOUT, 30); 110 | curl_setopt($ch, CURLOPT_URL, $url); 111 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 112 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 113 | curl_setopt($ch, CURLOPT_HEADER, FALSE); 114 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 115 | if (Wxpay::getConfig('curl_proxy_host') != '0.0.0.0' && Wxpay::getConfig('curl_proxy_port') != 0) { 116 | curl_setopt($ch, CURLOPT_PROXY, Wxpay::getConfig('curl_proxy_host')); 117 | curl_setopt($ch, CURLOPT_PROXYPORT, Wxpay::getConfig('curl_proxy_port')); 118 | } 119 | //运行curl,结果以jason形式返回 120 | $res = curl_exec($ch); 121 | curl_close($ch); 122 | //取出openid 123 | $data = json_decode($res, true); 124 | $this->data = $data; 125 | $openid = $data['openid']; 126 | return $openid; 127 | } 128 | 129 | /** 130 | * 131 | * 拼接签名字符串 132 | * @param array $urlObj 133 | * 134 | * @return 返回已经拼接好的字符串 135 | */ 136 | private function toUrlParams($urlObj) 137 | { 138 | $buff = ''; 139 | foreach ($urlObj as $k => $v) { 140 | if ($k != 'sign') { 141 | $buff .= $k . '=' . $v . '&'; 142 | } 143 | } 144 | 145 | $buff = trim($buff, '&'); 146 | return $buff; 147 | } 148 | 149 | /** 150 | * 151 | * 获取地址js参数 152 | * 153 | * @return 获取共享收货地址js函数需要的参数,json格式可以直接做参数使用 154 | */ 155 | public function GetEditAddressParameters() 156 | { 157 | $getData = $this->data; 158 | $data = array(); 159 | $data['appid'] = Wxpay::getConfig('appid'); 160 | $data['url'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 161 | $time = time(); 162 | $data['timestamp'] = '$time'; 163 | $data['noncestr'] = '1234568'; 164 | $data['accesstoken'] = $getData['access_token']; 165 | ksort($data); 166 | $params = $this->toUrlParams($data); 167 | $addrSign = sha1($params); 168 | 169 | $afterData = array( 170 | 'addrSign' => $addrSign, 171 | 'signType' => 'sha1', 172 | 'scope' => 'jsapi_address', 173 | 'appId' => Wxpay::getConfig('appid'), 174 | 'timeStamp' => $data['timestamp'], 175 | 'nonceStr' => $data['noncestr'] 176 | ); 177 | $parameters = json_encode($afterData); 178 | return $parameters; 179 | } 180 | 181 | /** 182 | * 183 | * 构造获取code的url连接 184 | * @param string $redirectUrl 微信服务器回跳的url,需要url编码 185 | * 186 | * @return 返回构造好的url 187 | */ 188 | private function __CreateOauthUrlForCode($redirectUrl) 189 | { 190 | $urlObj['appid'] = Wxpay::getConfig('appid'); 191 | $urlObj['redirect_uri'] = '$redirectUrl'; 192 | $urlObj['response_type'] = 'code'; 193 | $urlObj['scope'] = 'snsapi_base'; 194 | $urlObj['state'] = 'STATE' . '#wechat_redirect'; 195 | $bizString = $this->toUrlParams($urlObj); 196 | return 'https://open.weixin.qq.com/connect/oauth2/authorize?' . $bizString; 197 | } 198 | 199 | /** 200 | * 201 | * 构造获取open和access_toke的url地址 202 | * @param string $code,微信跳转带回的code 203 | * 204 | * @return 请求的url 205 | */ 206 | private function __CreateOauthUrlForOpenid($code) 207 | { 208 | $urlObj['appid'] = Wxpay::getConfig('appid'); 209 | $urlObj['secret'] = Wxpay::getConfig('appsecret'); 210 | $urlObj['code'] = $code; 211 | $urlObj['grant_type'] = 'authorization_code'; 212 | $bizString = $this->toUrlParams($urlObj); 213 | return 'https://api.weixin.qq.com/sns/oauth2/access_token?' . $bizString; 214 | } 215 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Pay/Micro.php: -------------------------------------------------------------------------------- 1 | config = $config; 46 | $this->api = new Api($config); 47 | 48 | $this->input = new MicroPay(); 49 | } 50 | 51 | public function __call($method, $arguments) 52 | { 53 | if (method_exists($this->input, $method)) { 54 | return call_user_func_array([ 55 | $this->input, 56 | $method 57 | ], $arguments); 58 | } 59 | return call_user_func_array([ 60 | $this, 61 | $method 62 | ], $arguments); 63 | } 64 | 65 | /** 66 | * 67 | * 提交刷卡支付,并且确认结果,接口比较慢 68 | * @param MicroPay $input 69 | * @throws WxpayException 70 | * @return 返回查询接口的结果 71 | */ 72 | public function pay() 73 | { 74 | //①、提交被扫支付 75 | $result = $this->api->micropay($this->input, 5); 76 | 77 | //如果返回成功 78 | if (! array_key_exists('return_code', $result) || ! array_key_exists('result_code', $result)) { 79 | // echo '接口调用失败,请确认是否输入是否有误!'; 80 | throw new WxpayException('接口调用失败!'); 81 | } 82 | 83 | //②、接口调用成功,明确返回调用失败 84 | if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'FAIL' && $result['err_code'] != 'USERPAYING' && $result['err_code'] != 'SYSTEMERROR') { 85 | throw new WxpayException($result['err_code_des']); 86 | } 87 | 88 | //签名验证 89 | $out_trade_no = $this->input->getOutTradeNo(); 90 | 91 | //③、确认支付是否成功 92 | $start_time = time(); 93 | while (time() - $start_time <= 30) { 94 | $succ_result = 0; 95 | $query_result = $this->query($out_trade_no, $succ_result); 96 | switch ($succ_result) { 97 | case 1: 98 | // 订单交易成功 99 | return $query_result; 100 | case 2: 101 | // 订单交易失败 102 | break 2; 103 | default: 104 | // 等待1s后继续 105 | sleep(1); 106 | } 107 | } 108 | 109 | //④、确认失败,则撤销订单 110 | if (! $this->cancel($out_trade_no)) { 111 | throw new WxpayException('撤销单失败!'); 112 | } 113 | 114 | return false; 115 | } 116 | 117 | /** 118 | * 119 | * 查询订单情况 120 | * @param string $out_trade_no 商户订单号 121 | * @param int $succ_code 查询订单结果 122 | * @return 0 状态不确定,1表示订单成功,2表示交易失败,3表示继续等待 123 | */ 124 | public function query($out_trade_no, &$succ_code) 125 | { 126 | $input = new OrderQuery(); 127 | $input->setOutTradeNo($out_trade_no); 128 | $result = $this->api->orderQuery($input); 129 | 130 | $succ_code = 0; 131 | if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { 132 | switch ($result['trade_state']) { 133 | case 'SUCCESS': // 支付成功 134 | // 订单成功 135 | $succ_code = 1; 136 | break; 137 | case 'REFUND': // 转入退款 138 | case 'CLOSED': // 已关闭 139 | case 'REVOKED': // 已撤销(刷卡支付) 140 | case 'PAYERROR': // 支付失败(其他原因,如银行返回失败) 141 | // 支付失败 142 | $succ_code = 2; 143 | break; 144 | case 'USERPAYING': // 用户支付中 145 | case 'NOTPAY': // 未支付 146 | // 继续等待 147 | $succ_code = 3; 148 | return false; 149 | } 150 | return $result; 151 | } 152 | // 执行到这里,就是网络或系统错误 153 | return false; 154 | } 155 | 156 | /** 157 | * 158 | * 撤销订单,如果失败会重复调用10次 159 | * @param string $out_trade_no 160 | */ 161 | public function cancel($out_trade_no) 162 | { 163 | $depth = 0; 164 | while ($depth ++ < 10) { 165 | $input = new Reverse(); 166 | $input->setOutTradeNo($out_trade_no); 167 | $result = $this->api->reverse($input); 168 | 169 | //接口调用失败 170 | if ($result['return_code'] != 'SUCCESS') { 171 | continue; 172 | } 173 | 174 | //如果结果为success且不需要重新调用撤销,则表示撤销成功 175 | if ($result['result_code'] != 'SUCCESS' && $result['recall'] == 'N') { 176 | return true; 177 | } elseif ($result['recall'] == 'Y') { 178 | continue; 179 | } 180 | return false; 181 | } 182 | return false; 183 | } 184 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Pay/Native.php: -------------------------------------------------------------------------------- 1 | config = $config; 24 | $this->api = new Api($config); 25 | } 26 | 27 | /** 28 | * 29 | * 生成扫描支付URL,模式一 30 | * @param BizPayUrlInput $bizUrlInfo 31 | */ 32 | public function getPrePayUrl($productId) 33 | { 34 | $biz = new BizPayUrl(); 35 | $biz->setProductId($productId); 36 | $values = $this->api->bizpayurl($biz); 37 | $url = 'weixin://wxpay/bizpayurl?' . $this->toUrlParams($values); 38 | return $url; 39 | } 40 | 41 | /** 42 | * 43 | * 参数数组转换为url参数 44 | * @param array $urlObj 45 | */ 46 | private function toUrlParams($urlObj) 47 | { 48 | $buff = ''; 49 | foreach ($urlObj as $k => $v) { 50 | $buff .= $k . '=' . $v . '&'; 51 | } 52 | 53 | $buff = trim($buff, '&'); 54 | return $buff; 55 | } 56 | 57 | /** 58 | * 59 | * 生成直接支付url,支付url有效期为2小时,模式二 60 | * @param UnifiedOrderInput $input 61 | */ 62 | public function GetPayUrl($input) 63 | { 64 | if ($input->GetTrade_type() == 'NATIVE') { 65 | $result = $this->api->unifiedOrder($input); 66 | return $result; 67 | } 68 | } 69 | 70 | /** 71 | * 转换短链接 72 | * @param string $url 73 | */ 74 | public function shortUrl($url){ 75 | $input = new ShortUrl(); 76 | $input->setLongUrl($url); 77 | $values = $this->api->shorturl($input); 78 | if($values['return_code'] === 'FAIL'){ 79 | throw new WxpayException($values['return_msg']); 80 | } 81 | return $values['short_url']; 82 | } 83 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Pay/Refund.php: -------------------------------------------------------------------------------- 1 | config = $config; 30 | $this->api = new Api($config); 31 | 32 | $this->input = new RefundModel(); 33 | } 34 | 35 | public function __call($method, $arguments) 36 | { 37 | if (method_exists($this->input, $method)) { 38 | return call_user_func_array([ 39 | $this->input, 40 | $method 41 | ], $arguments); 42 | } 43 | return call_user_func_array([ 44 | $this, 45 | $method 46 | ], $arguments); 47 | } 48 | 49 | /** 50 | * 执行退款 51 | */ 52 | public function refund() 53 | { 54 | $result = $this->api->refund($this->input); 55 | 56 | if (@$result['return_code'] != 'SUCCESS' || @$result['result_code'] != 'SUCCESS') { 57 | $message = '接口调用失败!'; 58 | if (key_exists('err_code_des', $result)) { 59 | $message = $result['err_code_des']; 60 | } 61 | throw new WxpayException($message); 62 | } 63 | 64 | return $result; 65 | } 66 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Sdk/Api.php: -------------------------------------------------------------------------------- 1 | config = $config; 35 | } 36 | 37 | /** 38 | * 39 | * 统一下单,UnifiedOrder中out_trade_no、body、total_fee、trade_type必填 40 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 41 | * @param UnifiedOrder $input 42 | * @param int $time_out 43 | * @throws WxPayException 44 | * @return 成功时返回,其他抛异常 45 | */ 46 | public function unifiedOrder($input, $time_out = 6) 47 | { 48 | $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; 49 | //检测必填参数 50 | if (! $input->isOutTradeNoSet()) { 51 | throw new WxPayException('缺少统一支付接口必填参数out_trade_no!'); 52 | } elseif (! $input->isBodySet()) { 53 | throw new WxPayException('缺少统一支付接口必填参数body!'); 54 | } elseif (! $input->isTotalFeeSet()) { 55 | throw new WxPayException('缺少统一支付接口必填参数total_fee!'); 56 | } elseif (! $input->isTradeTypeSet()) { 57 | throw new WxPayException('缺少统一支付接口必填参数trade_type!'); 58 | } 59 | 60 | //关联参数 61 | if ($input->getTradeType() == 'JSAPI' && ! $input->isOpenidSet()) { 62 | throw new WxPayException('统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!'); 63 | } 64 | if ($input->getTradeType() == 'NATIVE' && ! $input->isProductIdSet()) { 65 | throw new WxPayException('统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!'); 66 | } 67 | 68 | //异步通知url未设置,则使用配置文件中的url 69 | if (! $input->isNotifyUrlSet()) { 70 | $notify_url = Wxpay::getConfig('notify_url'); 71 | if (! preg_match('#^https?://#i', $notify_url)) { 72 | $notify_url = rtrim(config('app.url'), '/') . '/' . ltrim($notify_url, '/'); 73 | } 74 | $input->setNotifyUrl($notify_url); //异步通知url 75 | } 76 | 77 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 78 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 79 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 80 | $input->setSpbillCreateIp($_SERVER['REMOTE_ADDR']); //终端ip 81 | //$input->setSpbillCreateIp('1.1.1.1'); 82 | $input->setNonceStr($this->getNonceStr()); //随机字符串 83 | 84 | 85 | //签名 86 | $input->setSign(); 87 | $xml = $input->toXml(); 88 | 89 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 90 | $response = $this->postXmlCurl($xml, $url, false, $time_out); 91 | $result = Results::Init($response); 92 | $this->reportCostTime($url, $start_time_stamp, $result); //上报请求花费时间 93 | 94 | 95 | return $result; 96 | } 97 | 98 | /** 99 | * 100 | * 查询订单,OrderQuery中out_trade_no、transaction_id至少填一个 101 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 102 | * @param OrderQuery $input 103 | * @param int $time_out 104 | * @throws WxPayException 105 | * @return 成功时返回,其他抛异常 106 | */ 107 | public function orderQuery($input, $time_out = 6) 108 | { 109 | $url = 'https://api.mch.weixin.qq.com/pay/orderquery'; 110 | //检测必填参数 111 | if (! $input->isOutTradeNoSet() && ! $input->isTransactionIdSet()) { 112 | throw new WxPayException('订单查询接口中,out_trade_no、transaction_id至少填一个!'); 113 | } 114 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 115 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 116 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 117 | $input->setNonceStr($this->getNonceStr()); //随机字符串 118 | 119 | 120 | $input->setSign(); //签名 121 | $xml = $input->toXml(); 122 | 123 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 124 | $response = $this->postXmlCurl($xml, $url, false, $time_out); 125 | $result = Results::Init($response); 126 | $this->reportCostTime($url, $start_time_stamp, $result); //上报请求花费时间 127 | 128 | 129 | return $result; 130 | } 131 | 132 | /** 133 | * 134 | * 关闭订单,CloseOrder中out_trade_no必填 135 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 136 | * @param CloseOrder $input 137 | * @param int $time_out 138 | * @throws WxPayException 139 | * @return 成功时返回,其他抛异常 140 | */ 141 | public function closeOrder($input, $time_out = 6) 142 | { 143 | $url = 'https://api.mch.weixin.qq.com/pay/closeorder'; 144 | //检测必填参数 145 | if (! $input->isOutTradeNoSet()) { 146 | throw new WxPayException('订单查询接口中,out_trade_no必填!'); 147 | } 148 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 149 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 150 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 151 | $input->setNonceStr($this->getNonceStr()); //随机字符串 152 | 153 | 154 | $input->setSign(); //签名 155 | $xml = $input->toXml(); 156 | 157 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 158 | $response = $this->postXmlCurl($xml, $url, false, $time_out); 159 | $result = Results::Init($response); 160 | $this->reportCostTime($url, $start_time_stamp, $result); //上报请求花费时间 161 | 162 | 163 | return $result; 164 | } 165 | 166 | /** 167 | * 168 | * 申请退款,Refund中out_trade_no、transaction_id至少填一个且 169 | * out_refund_no、total_fee、refund_fee、op_user_id为必填参数 170 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 171 | * @param Refund $input 172 | * @param int $time_out 173 | * @throws WxPayException 174 | * @return 成功时返回,其他抛异常 175 | */ 176 | public function refund($input, $time_out = 6) 177 | { 178 | $url = 'https://api.mch.weixin.qq.com/secapi/pay/refund'; 179 | //检测必填参数 180 | if (! $input->isOutTradeNoSet() && ! $input->isTransactionIdSet()) { 181 | throw new WxPayException('退款申请接口中,out_trade_no、transaction_id至少填一个!'); 182 | } elseif (! $input->isOutRefundNoSet()) { 183 | throw new WxPayException('退款申请接口中,缺少必填参数out_refund_no!'); 184 | } elseif (! $input->isTotalFeeSet()) { 185 | throw new WxPayException('退款申请接口中,缺少必填参数total_fee!'); 186 | } elseif (! $input->isRefundFeeSet()) { 187 | throw new WxPayException('退款申请接口中,缺少必填参数refund_fee!'); 188 | } elseif (! $input->isOpUserIdSet()) { 189 | throw new WxPayException('退款申请接口中,缺少必填参数op_user_id!'); 190 | } 191 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 192 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 193 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 194 | $input->setNonceStr($this->getNonceStr()); //随机字符串 195 | 196 | 197 | $input->setSign(); //签名 198 | $xml = $input->toXml(); 199 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 200 | $response = $this->postXmlCurl($xml, $url, true, $time_out); 201 | $result = Results::Init($response); 202 | $this->reportCostTime($url, $start_time_stamp, $result); //上报请求花费时间 203 | 204 | 205 | return $result; 206 | } 207 | 208 | /** 209 | * 210 | * 查询退款 211 | * 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时, 212 | * 用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。 213 | * RefundQuery中out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个 214 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 215 | * @param RefundQuery $input 216 | * @param int $time_out 217 | * @throws WxPayException 218 | * @return 成功时返回,其他抛异常 219 | */ 220 | public function refundQuery($input, $time_out = 6) 221 | { 222 | $url = 'https://api.mch.weixin.qq.com/pay/refundquery'; 223 | //检测必填参数 224 | if (! $input->isOutRefundNoSet() && ! $input->isOutTradeNoSet() && ! $input->isTransactionIdSet() && ! $input->isRefundIdSet()) { 225 | throw new WxPayException('退款查询接口中,out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个!'); 226 | } 227 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 228 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 229 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 230 | $input->setNonceStr($this->getNonceStr()); //随机字符串 231 | 232 | 233 | $input->setSign(); //签名 234 | $xml = $input->toXml(); 235 | 236 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 237 | $response = $this->postXmlCurl($xml, $url, false, $time_out); 238 | $result = Results::Init($response); 239 | $this->reportCostTime($url, $start_time_stamp, $result); //上报请求花费时间 240 | 241 | 242 | return $result; 243 | } 244 | 245 | /** 246 | * 下载对账单,DownloadBill中bill_date为必填参数 247 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 248 | * @param DownloadBill $input 249 | * @param int $time_out 250 | * @throws WxPayException 251 | * @return 成功时返回,其他抛异常 252 | */ 253 | public function downloadBill($input, $time_out = 6) 254 | { 255 | $url = 'https://api.mch.weixin.qq.com/pay/downloadbill'; 256 | //检测必填参数 257 | if (! $input->isBillDateSet()) { 258 | throw new WxPayException('对账单接口中,缺少必填参数bill_date!'); 259 | } 260 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 261 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 262 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 263 | $input->setNonceStr($this->getNonceStr()); //随机字符串 264 | 265 | 266 | $input->setSign(); //签名 267 | $xml = $input->toXml(); 268 | 269 | $response = $this->postXmlCurl($xml, $url, false, $time_out); 270 | if (substr($response, 0, 5) == '') { 271 | return ''; 272 | } 273 | return $response; 274 | } 275 | 276 | /** 277 | * 提交被扫支付API 278 | * 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台, 279 | * 由商户收银台或者商户后台调用该接口发起支付。 280 | * MicroPay中body、out_trade_no、total_fee、auth_code参数必填 281 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 282 | * @param MicroPay $input 283 | * @param int $time_out 284 | */ 285 | public function micropay($input, $time_out = 10) 286 | { 287 | $url = 'https://api.mch.weixin.qq.com/pay/micropay'; 288 | //检测必填参数 289 | if (! $input->isBodySet()) { 290 | throw new WxPayException('提交被扫支付API接口中,缺少必填参数body!'); 291 | } elseif (! $input->isOutTradeNoSet()) { 292 | throw new WxPayException('提交被扫支付API接口中,缺少必填参数out_trade_no!'); 293 | } elseif (! $input->isTotalFeeSet()) { 294 | throw new WxPayException('提交被扫支付API接口中,缺少必填参数total_fee!'); 295 | } elseif (! $input->isAuthCodeSet()) { 296 | throw new WxPayException('提交被扫支付API接口中,缺少必填参数auth_code!'); 297 | } 298 | 299 | $input->setSpbillCreateIp($_SERVER['REMOTE_ADDR']); //终端ip 300 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 301 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 302 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 303 | $input->setNonceStr($this->getNonceStr()); //随机字符串 304 | 305 | 306 | $input->setSign(); //签名 307 | $xml = $input->toXml(); 308 | 309 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 310 | $response = $this->postXmlCurl($xml, $url, false, $time_out); 311 | $result = Results::Init($response); 312 | $this->reportCostTime($url, $start_time_stamp, $result); //上报请求花费时间 313 | 314 | 315 | return $result; 316 | } 317 | 318 | /** 319 | * 320 | * 撤销订单API接口,Reverse中参数out_trade_no和transaction_id必须填写一个 321 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 322 | * @param Reverse $input 323 | * @param int $time_out 324 | * @throws WxPayException 325 | */ 326 | public function reverse($input, $time_out = 6) 327 | { 328 | $url = 'https://api.mch.weixin.qq.com/secapi/pay/reverse'; 329 | //检测必填参数 330 | if (! $input->isOutTradeNoSet() && ! $input->isTransactionIdSet()) { 331 | throw new WxPayException('撤销订单API接口中,参数out_trade_no和transaction_id必须填写一个!'); 332 | } 333 | 334 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 335 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 336 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 337 | $input->setNonceStr($this->getNonceStr()); //随机字符串 338 | 339 | 340 | $input->setSign(); //签名 341 | $xml = $input->toXml(); 342 | 343 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 344 | $response = $this->postXmlCurl($xml, $url, true, $time_out); 345 | $result = Results::Init($response); 346 | $this->reportCostTime($url, $start_time_stamp, $result); //上报请求花费时间 347 | 348 | 349 | return $result; 350 | } 351 | 352 | /** 353 | * 354 | * 测速上报,该方法内部封装在report中,使用时请注意异常流程 355 | * Report中interface_url、return_code、result_code、user_ip、execute_time_必填 356 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 357 | * @param Report $input 358 | * @param int $time_out 359 | * @throws WxPayException 360 | * @return 成功时返回,其他抛异常 361 | */ 362 | public function report($input, $time_out = 1) 363 | { 364 | $url = 'https://api.mch.weixin.qq.com/payitil/report'; 365 | //检测必填参数 366 | if (! $input->isInterfaceUrlSet()) { 367 | throw new WxPayException('接口URL,缺少必填参数interface_url!'); 368 | } 369 | if (! $input->isReturnCodeSet()) { 370 | throw new WxPayException('返回状态码,缺少必填参数return_code!'); 371 | } 372 | if (! $input->isResultCodeSet()) { 373 | throw new WxPayException('业务结果,缺少必填参数result_code!'); 374 | } 375 | if (! $input->isUserIpSet()) { 376 | throw new WxPayException('访问接口IP,缺少必填参数user_ip!'); 377 | } 378 | if (! $input->isExecuteTimeSet()) { 379 | throw new WxPayException('接口耗时,缺少必填参数execute_time_!'); 380 | } 381 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 382 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 383 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 384 | $input->setUserIp($_SERVER['REMOTE_ADDR']); //终端ip 385 | $input->setTime(date('YmdHis')); //商户上报时间 386 | $input->setNonceStr($this->getNonceStr()); //随机字符串 387 | 388 | 389 | $input->setSign(); //签名 390 | $xml = $input->toXml(); 391 | 392 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 393 | $response = $this->postXmlCurl($xml, $url, false, $time_out); 394 | return $response; 395 | } 396 | 397 | /** 398 | * 399 | * 生成二维码规则,模式一生成支付二维码 400 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 401 | * @param BizPayUrl $input 402 | * @param int $time_out 403 | * @throws WxPayException 404 | * @return 成功时返回,其他抛异常 405 | */ 406 | public function bizpayurl($input, $time_out = 6) 407 | { 408 | if (! $input->isProductIdSet()) { 409 | throw new WxPayException('生成二维码,缺少必填参数product_id!'); 410 | } 411 | 412 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 413 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 414 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 415 | $input->setTimeStamp(time()); //时间戳 416 | $input->setNonceStr($this->getNonceStr()); //随机字符串 417 | 418 | 419 | $input->setSign(); //签名 420 | 421 | 422 | return $input->getValues(); 423 | } 424 | 425 | /** 426 | * 427 | * 转换短链接 428 | * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX), 429 | * 减小二维码数据量,提升扫描速度和精确度。 430 | * appid、mchid、spbill_create_ip、nonce_str不需要填入 431 | * @param ShortUrl $input 432 | * @param int $time_out 433 | * @throws WxPayException 434 | * @return 成功时返回,其他抛异常 435 | */ 436 | public function shorturl($input, $time_out = 6) 437 | { 438 | $url = 'https://api.mch.weixin.qq.com/tools/shorturl'; 439 | //检测必填参数 440 | if (! $input->isLongUrlSet()) { 441 | throw new WxPayException('需要转换的URL,签名用原串,传输需URL encode!'); 442 | } 443 | $input->setAppid(Wxpay::getConfig('appid')); //公众账号ID 444 | $input->setMchId(Wxpay::getConfig('mchid')); //商户号 445 | $input->setSubMchId(Wxpay::getConfig('sub_mch_id')); //子商户号 446 | $input->setNonceStr($this->getNonceStr()); //随机字符串 447 | 448 | 449 | $input->setSign(); //签名 450 | $xml = $input->toXml(); 451 | 452 | $start_time_stamp = $this->getMillisecond(); //请求开始时间 453 | $response = $this->postXmlCurl($xml, $url, false, $time_out); 454 | $result = Results::Init($response); 455 | $this->reportCostTime($url, $start_time_stamp, $result); //上报请求花费时间 456 | 457 | 458 | return $result; 459 | } 460 | 461 | /** 462 | * 463 | * 支付结果通用通知 464 | * @param function $callback 465 | * 直接回调函数使用方法: notify(you_function); 466 | * 回调类成员函数方法:notify(array($this, you_function)); 467 | * $callback 原型为:function function_name($data){} 468 | */ 469 | public function notify($callback, &$msg) 470 | { 471 | //获取通知的数据 472 | // $xml = $GLOBALS['HTTP_RAW_POST_DATA']; 473 | $xml = file_get_contents('php://input'); 474 | //如果返回成功则验证签名 475 | try { 476 | $result = Results::Init($xml); 477 | } catch (WxPayException $e) { 478 | $msg = $e->errorMessage(); 479 | return false; 480 | } 481 | 482 | return call_user_func($callback, $result, $msg); 483 | } 484 | 485 | /** 486 | * 487 | * 产生随机字符串,不长于32位 488 | * @param int $length 489 | * @return 产生的随机字符串 490 | */ 491 | public function getNonceStr($length = 32) 492 | { 493 | $chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; 494 | $str = ''; 495 | for ($i = 0; $i < $length; $i ++) { 496 | $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); 497 | } 498 | return $str; 499 | } 500 | 501 | /** 502 | * 直接输出xml 503 | * @param string $xml 504 | */ 505 | public function replyNotify($xml) 506 | { 507 | echo $xml; 508 | } 509 | 510 | /** 511 | * 512 | * 上报数据, 上报的时候将屏蔽所有异常流程 513 | * @param string $usrl 514 | * @param int $start_time_stamp 515 | * @param array $data 516 | */ 517 | private function reportCostTime($url, $start_time_stamp, $data) 518 | { 519 | //如果不需要上报数据 520 | if (Wxpay::getConfig('report_levenl') == 0) { 521 | return; 522 | } 523 | //如果仅失败上报 524 | if (Wxpay::getConfig('report_levenl') == 1 && array_key_exists('return_code', $data) && $data['return_code'] == 'SUCCESS' && array_key_exists('result_code', $data) && $data['result_code'] == 'SUCCESS') { 525 | return; 526 | } 527 | 528 | //上报逻辑 529 | $endTimeStamp = $this->getMillisecond(); 530 | $objInput = new Report(); 531 | $objInput->setInterfaceUrl($url); 532 | $objInput->setExecuteTime($endTimeStamp - $start_time_stamp); 533 | //返回状态码 534 | if (array_key_exists('return_code', $data)) { 535 | $objInput->setReturnCode($data['return_code']); 536 | } 537 | //返回信息 538 | if (array_key_exists('return_msg', $data)) { 539 | $objInput->setReturnMsg($data['return_msg']); 540 | } 541 | //业务结果 542 | if (array_key_exists('result_code', $data)) { 543 | $objInput->setResultCode($data['result_code']); 544 | } 545 | //错误代码 546 | if (array_key_exists('err_code', $data)) { 547 | $objInput->setErrCode($data['err_code']); 548 | } 549 | //错误代码描述 550 | if (array_key_exists('err_code_des', $data)) { 551 | $objInput->setErrCodeDes($data['err_code_des']); 552 | } 553 | //商户订单号 554 | if (array_key_exists('out_trade_no', $data)) { 555 | $objInput->setOutTradeNo($data['out_trade_no']); 556 | } 557 | //设备号 558 | if (array_key_exists('device_info', $data)) { 559 | $objInput->setDeviceInfo($data['device_info']); 560 | } 561 | 562 | try { 563 | $this->report($objInput); 564 | } catch (WxPayException $e) { 565 | //不做任何处理 566 | } 567 | } 568 | 569 | /** 570 | * 以post方式提交xml到对应的接口url 571 | * 572 | * @param string $xml 需要post的xml数据 573 | * @param string $url url 574 | * @param bool $useCert 是否需要证书,默认不需要 575 | * @param int $second url执行超时时间,默认30s 576 | * @throws WxPayException 577 | */ 578 | private function postXmlCurl($xml, $url, $useCert = false, $second = 30) 579 | { 580 | $ch = curl_init(); 581 | //设置超时 582 | curl_setopt($ch, CURLOPT_TIMEOUT, $second); 583 | 584 | //如果有配置代理这里就设置代理 585 | if (Wxpay::getConfig('curl_proxy_host') != '0.0.0.0' && Wxpay::getConfig('curl_proxy_port') != 0) { 586 | curl_setopt($ch, CURLOPT_PROXY, Wxpay::getConfig('curl_proxy_host')); 587 | curl_setopt($ch, CURLOPT_PROXYPORT, Wxpay::getConfig('curl_proxy_port')); 588 | } 589 | curl_setopt($ch, CURLOPT_URL, $url); 590 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 591 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //严格校验 592 | //设置header 593 | curl_setopt($ch, CURLOPT_HEADER, FALSE); 594 | //要求结果为字符串且输出到屏幕上 595 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 596 | 597 | if ($useCert == true) { 598 | //设置证书 599 | //使用证书:cert 与 key 分别属于两个.pem文件 600 | curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM'); 601 | curl_setopt($ch, CURLOPT_SSLCERT, Wxpay::getConfig('sslcert_path')); 602 | curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM'); 603 | curl_setopt($ch, CURLOPT_SSLKEY, Wxpay::getConfig('sslkey_path')); 604 | } 605 | //post提交方式 606 | curl_setopt($ch, CURLOPT_POST, TRUE); 607 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 608 | //运行curl 609 | $data = curl_exec($ch); 610 | //返回结果 611 | if ($data) { 612 | curl_close($ch); 613 | return $data; 614 | } else { 615 | $error = curl_errno($ch); 616 | curl_close($ch); 617 | throw new WxPayException('curl出错,错误码:' . $error); 618 | } 619 | } 620 | 621 | /** 622 | * 获取毫秒级别的时间戳 623 | */ 624 | private function getMillisecond() 625 | { 626 | //获取毫秒的时间戳 627 | $time = explode(' ', microtime()); 628 | $time = $time[1] . ($time[0] * 1000); 629 | $time2 = explode('.', $time); 630 | $time = $time2[0]; 631 | return $time; 632 | } 633 | } 634 | 635 | -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Sdk/Notify.php: -------------------------------------------------------------------------------- 1 | config = $config; 21 | $this->api = new Api($config); 22 | } 23 | 24 | /** 25 | * 26 | * 回调入口 27 | * @param bool $needSign 是否需要签名输出 28 | */ 29 | final public function handle($callback, $needSign = true) 30 | { 31 | $msg = 'OK'; 32 | //当返回false的时候,表示notify中调用NotifyCallBack回调失败获取签名校验失败,此时直接回复失败 33 | $result = $this->api->notify($callback, $msg); 34 | if ($result == false) { 35 | $this->setReturnCode('FAIL'); 36 | $this->setReturnMsg($msg); 37 | return $this->replyNotify(false); 38 | } else { 39 | //该分支在成功回调到NotifyCallBack方法,处理完成之后流程 40 | $this->setReturnCode('SUCCESS'); 41 | $this->setReturnMsg('OK'); 42 | } 43 | return $this->replyNotify($needSign); 44 | } 45 | 46 | /** 47 | * 48 | * 回复通知 49 | * @param bool $needSign 是否需要签名输出 50 | */ 51 | final private function replyNotify($need_sign = true) 52 | { 53 | //如果需要签名 54 | if ($need_sign == true && $this->getReturnCode() == 'SUCCESS') { 55 | $this->setSign(); 56 | } 57 | return $this->toXml(); 58 | } 59 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/Wxpay.php: -------------------------------------------------------------------------------- 1 | config = $config; 22 | } 23 | 24 | public function getConfig($name = null) 25 | { 26 | if (is_null($name)) { 27 | return $this->config; 28 | } 29 | return array_get($this->config, $name, null); 30 | } 31 | 32 | public function getAccessToken() 33 | { 34 | $key = 'Wxpay/access_token'; 35 | if (Cache::has($key)) { 36 | return Cache::get($key); 37 | } 38 | 39 | $curl = new Curl(); 40 | $curl->get('https://api.weixin.qq.com/cgi-bin/token', [ 41 | 'grant_type' => 'client_credential', 42 | 'appid' => $this->config['appid'], 43 | 'secret' => $this->config['appsecret'] 44 | ]); 45 | if ($curl->error) { 46 | throw new WxPayException('curl错误:' . $curl->error_code); 47 | } 48 | $json = json_decode($curl->response, true); 49 | if (key_exists('errcode', $json)) { 50 | throw new WxPayException($json['errmsg'], $json['errcode']); 51 | } 52 | $access_token = $json['access_token']; 53 | $expires_at = Carbon::now()->addSeconds($json['expires_in'] - 60); 54 | Cache::put($key, $access_token, $expires_at); 55 | 56 | return $access_token; 57 | } 58 | 59 | public function getJsapiTicket() 60 | { 61 | $key = 'Wxpay/jsapi_ticket'; 62 | if (Cache::has($key)) { 63 | return Cache::get($key); 64 | } 65 | 66 | $curl = new Curl(); 67 | $curl->get('https://api.weixin.qq.com/cgi-bin/ticket/getticket', [ 68 | 'type' => 'jsapi', 69 | 'access_token' => $this->getAccessToken() 70 | ]); 71 | if ($curl->error) { 72 | throw new WxPayException('curl错误:' . $curl->error_code); 73 | } 74 | $json = json_decode($curl->response, true); 75 | if ((int) $json['errcode'] > 0) { 76 | throw new WxPayException($json['errmsg'], $json['errcode']); 77 | } 78 | $ticket = $json['ticket']; 79 | $expires_at = Carbon::now()->addSeconds($json['expires_in'] - 60); 80 | Cache::put($key, $ticket, $expires_at); 81 | 82 | return $ticket; 83 | } 84 | 85 | public function getSignature() 86 | { 87 | static $cache = null; 88 | 89 | if (is_null($cache)) { 90 | $data = [ 91 | 'timestamp' => (string) time(), 92 | 'noncestr' => str_random(16), 93 | 'jsapi_ticket' => $this->getJsapiTicket(), 94 | 'url' => Request::getUri() 95 | ]; 96 | ksort($data); 97 | $params = []; 98 | foreach ($data as $k => $v) { 99 | $params[] = $k . '=' . $v; 100 | } 101 | $params = join('&', $params); 102 | $signature = sha1($params); 103 | 104 | $cache = new \stdClass(); 105 | $cache->timestamp = $data['timestamp']; 106 | $cache->noncestr = $data['noncestr']; 107 | $cache->signature = $signature; 108 | } 109 | 110 | return $cache; 111 | } 112 | 113 | /** 114 | * 刷卡支付 115 | */ 116 | public function micro() 117 | { 118 | return new Micro($this->config); 119 | } 120 | 121 | /** 122 | * 申请退款 123 | */ 124 | public function refund() 125 | { 126 | return new Refund($this->config); 127 | } 128 | 129 | /** 130 | * 扫码支付 131 | */ 132 | public function native() 133 | { 134 | return new Native($this->config); 135 | } 136 | 137 | /** 138 | * 核心API对象 139 | */ 140 | public function api() 141 | { 142 | return new Api($this->config); 143 | } 144 | 145 | /** 146 | * 通用通知 147 | */ 148 | public function notify() 149 | { 150 | return new Notify($this->config); 151 | } 152 | } -------------------------------------------------------------------------------- /src/Latrell/Wxpay/WxpayException.php: -------------------------------------------------------------------------------- 1 | getMessage(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Latrell/Wxpay/WxpayServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 15 | __DIR__ . '/../../config/config.php' => config_path('latrell-wxpay.php'), 16 | __DIR__ . '/../../config/cert/apiclient_cert.pem' => config_path('wxpay/cert/apiclient_cert.pem'), 17 | __DIR__ . '/../../config/cert/apiclient_key.pem' => config_path('wxpay/cert/apiclient_key.pem') 18 | ], 'config'); 19 | } 20 | 21 | /** 22 | * Register the service provider. 23 | * 24 | * @return void 25 | */ 26 | public function register() 27 | { 28 | $this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'latrell-wxpay'); 29 | 30 | $this->app->singleton('wxpay', function ($app) { 31 | return new Wxpay($app->config->get('latrell-wxpay')); 32 | }); 33 | 34 | $this->app->singleton('wxpay.jsapi', function ($app) { 35 | return new Pay\JsApi($app->config->get('latrell-wxpay')); 36 | }); 37 | 38 | $this->app->singleton('wxpay.micro', function ($app) { 39 | return new Pay\Micro($app->config->get('latrell-wxpay')); 40 | }); 41 | 42 | $this->app->singleton('wxpay.native', function ($app) { 43 | return new Pay\Native($app->config->get('latrell-wxpay')); 44 | }); 45 | } 46 | 47 | /** 48 | * Get the services provided by the provider. 49 | * 50 | * @return array 51 | */ 52 | public function provides() 53 | { 54 | return [ 55 | 'wxpay', 56 | 'wxpay.jsapi', 57 | 'wxpay.micro', 58 | 'wxpay.native' 59 | ]; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/config/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latrell/Wxpay/04f3a302480ccfe224017d21825d3f05eba6e1ea/src/config/.gitkeep -------------------------------------------------------------------------------- /src/config/cert/apiclient_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEdjCCA9+gAwIBAgICdTcwDQYJKoZIhvcNAQEFBQAwgYoxCzAJBgNVBAYTAkNO 3 | MRIwEAYDVQQIEwlHdWFuZ2RvbmcxETAPBgNVBAcTCFNoZW56aGVuMRAwDgYDVQQK 4 | EwdUZW5jZW50MQwwCgYDVQQLEwNXWEcxEzARBgNVBAMTCk1tcGF5bWNoQ0ExHzAd 5 | BgkqhkiG9w0BCQEWEG1tcGF5bWNoQHRlbmNlbnQwHhcNMTQxMjExMTE0ODA1WhcN 6 | MjQxMjA4MTE0ODA1WjCBpzELMAkGA1UEBhMCQ04xEjAQBgNVBAgTCUd1YW5nZG9u 7 | ZzERMA8GA1UEBxMIU2hlbnpoZW4xEDAOBgNVBAoTB1RlbmNlbnQxDjAMBgNVBAsT 8 | BU1NUGF5MTwwOgYDVQQDFDPkuK3lm73lnLDotKjlpKflrabvvIjmrabmsYnvvInm 9 | lZnogrLlj5HlsZXln7rph5HkvJoxETAPBgNVBAQTCDEwMDYwMjY4MIIBIjANBgkq 10 | hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2lfWB/a41ppF+siCZkCVwYyLxRixuOwq 11 | EcajtHCS0zqCzF4/LHHX9yDZJqETWtPbPX2UYJIaug2/yMT/wzK0kxrDi1LOIqYo 12 | 13wIJ0sntE6Bvb48JTfO6RtjOXD+Xane2pPzkMkpy7MAN+bXCjYWHuQ/4jj2bF8I 13 | y31j0AcS10kjI6O2athkMSRQ/JNMNyGCiuHe2gbLfbGTeG+3m14gxWcYJMbVxd7j 14 | SRpb7uh90wHqOVaYpsgd2SXulbXqHvPYUuJZdecn1gAbN1OFnnHyJfovbX5x2TK+ 15 | rBr1xC7JHbvqfNTC9RdGjjCwdV1m7x3UsX61Sljt1fZ0666NzaUwjwIDAQABo4IB 16 | RjCCAUIwCQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdIkNFUy1DQSBHZW5lcmF0 17 | ZSBDZXJ0aWZpY2F0ZSIwHQYDVR0OBBYEFDa6vd5UCEPP9qL20yo0+PsLMKnvMIG/ 18 | BgNVHSMEgbcwgbSAFD4FJvYiYrQVW4jNZH6w1GKn5YZ0oYGQpIGNMIGKMQswCQYD 19 | VQQGEwJDTjESMBAGA1UECBMJR3Vhbmdkb25nMREwDwYDVQQHEwhTaGVuemhlbjEQ 20 | MA4GA1UEChMHVGVuY2VudDEMMAoGA1UECxMDV1hHMRMwEQYDVQQDEwpNbXBheW1j 21 | aENBMR8wHQYJKoZIhvcNAQkBFhBtbXBheW1jaEB0ZW5jZW50ggkAu1SXK7wA6Fcw 22 | DgYDVR0PAQH/BAQDAgbAMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMCMA0GCSqGSIb3 23 | DQEBBQUAA4GBAEiS/XnCrRXJG2NKJpW/l/7eu1yqi5XAQ3OiTilSQGiD1Pu3uuUy 24 | 141ZGSoRxtsdPelOSfYKhLFHzDoqK82UsviMfUpeZq7vW3ZoTL7bMKgI3GJnGsRk 25 | 4Wb/0JkmQJckhSKqM6FSEWrCFENK7HuPirlaztLhGRcZwXtPXqBLfooa 26 | -----END CERTIFICATE----- 27 | -------------------------------------------------------------------------------- /src/config/cert/apiclient_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEA2lfWB/a41ppF+siCZkCVwYyLxRixuOwqEcajtHCS0zqCzF4/ 3 | LHHX9yDZJqETWtPbPX2UYJIaug2/yMT/wzK0kxrDi1LOIqYo13wIJ0sntE6Bvb48 4 | JTfO6RtjOXD+Xane2pPzkMkpy7MAN+bXCjYWHuQ/4jj2bF8Iy31j0AcS10kjI6O2 5 | athkMSRQ/JNMNyGCiuHe2gbLfbGTeG+3m14gxWcYJMbVxd7jSRpb7uh90wHqOVaY 6 | psgd2SXulbXqHvPYUuJZdecn1gAbN1OFnnHyJfovbX5x2TK+rBr1xC7JHbvqfNTC 7 | 9RdGjjCwdV1m7x3UsX61Sljt1fZ0666NzaUwjwIDAQABAoIBAQDEATXR0Fn9zGAl 8 | 0Pm+cRv+s/yE4rYoG1lou7kZsjUcCdqBO9naPBhzcLl/Q/nr/2NAwAsC5iW3/7+6 9 | q54tzMbth4ki+SKzWBYx2tY27/CknBU8EBpODttfx4Y7eoPd8TBtZ4Ou5ebvRbFc 10 | fY1tTUBuWtg+bIRKpMVwZw/DH5Z6SzUHrDZNCY7h57GVKZVgjeq1upDfvy+fIf+x 11 | 42KW1byhSi2WirD6D547u3pDk9KBxmnPXjJxkDQ5iHRKM1zG3yxTBQ56SHMJ7uw1 12 | AV9dtGDzO4TQGBLS16gfKVyGdjfkM4zmZDvOXxYB5Rbv0iJuTwEA/SENCkaYnBxv 13 | +byughqBAoGBAPBVmJjM8SS/fkinJ4K9ka9BiWyo8xmi2RIslyx32zuZI3XfzMfn 14 | 2j0URN2IgpPL+4S1rdjYrJ35cbPhN9wIF9J/bb2lsOlno/+9dSbN1nO0nHpmQwKv 15 | +dh+rwdlDaV58p9hdjFXKDd8uv6hfJjpkwsmZubJPXrPGFOF22FhRRojAoGBAOiT 16 | Ru4GVj414mEvW94J8YaMFwrT7Cb3YjjxL0Xj1zE9OOq+JxEeanhYgf2sTpB4HzOA 17 | JKsg4F2CAd4G0mgQ47ykzYJneGV6iPydzdnXRloi/LBQI9HWZWjUBUHrMmmiWBVQ 18 | w7hQvsqx9bDmtMs8HpkEUB84uIAsPi/Tl4WkkMilAoGADLA4Mjj/sjT58dQBXgGs 19 | I1iObNIuo3fZhgAcqxhY1rirCpoaMaOn/fmH+TovyqXGTadZ2kz2MBDvU9PcIx26 20 | RD6+CHkq8eeq3OGfwcC0Rb+PU1b6yrWHt0pY60cGhWn+yTNYDhrP4L4REUhtT5Vl 21 | Uf1hCWYufMFaQ26ZunZsM4kCgYBO/QYP/RL5We+itiTrSlE/MwD4anU/3rD7Sd6W 22 | TAVf8b0M7Lvz8nKSoOy1LPoZ0tI1+YV6oVXSLD9aGtMHCQVvokEx0tZvEKjJswag 23 | v55jKpLLhsxDjh8u9SM7+hdLDRoBU0bFqJbD3KDnDdPFWovByFc141u2HFCaibBi 24 | cTvDCQKBgHCRbP/p9/8CJeFGWGdBIUDhJWLg39HQgSfIdN9qg3CJ7GMwO3MN5leL 25 | qT2v8GfNfzrnCKyCuV17U82D1MiWAR/LVW9/OwOoQG9l1QYLNhuPoNW72MtCuxtA 26 | HQD/8706yQZzLwdnDzUTuhQxJJtb1++pnNOBwi4NL0VfuYsO0/t1 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | 'wx426b3015555a46be', 22 | 'mchid' => '1225312702', 23 | 'key' => 'e10adc3949ba59abbe56e057f20f883e', 24 | 'appsecret' => '01c6d59a3f9024db6336662ac95c8e74', 25 | 26 | 'sub_mch_id' => '', // 受理机构必须提供子商户号。 27 | 28 | //=======【证书路径设置】===================================== 29 | /** 30 | * TODO:设置商户证书路径 31 | * 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要,可登录商户平台下载, 32 | * API证书下载地址:https://pay.weixin.qq.com/index.php/account/api_cert,下载之前需要安装商户操作证书) 33 | * @var path 34 | */ 35 | 'sslcert_path' => config_path('wxpay/cert/apiclient_cert.pem'), 36 | 'sslkey_path' => config_path('wxpay/cert/apiclient_key.pem'), 37 | 38 | //=======【curl代理设置】=================================== 39 | /** 40 | * TODO:这里设置代理机器,只有需要代理的时候才设置,不需要代理,请设置为0.0.0.0和0 41 | * 本例程通过curl使用HTTP POST方法,此处可修改代理服务器, 42 | * 默认CURL_PROXY_HOST=0.0.0.0和CURL_PROXY_PORT=0,此时不开启代理(如有需要才设置) 43 | * @var unknown_type 44 | */ 45 | 'curl_proxy_host' => '0.0.0.0',//'10.152.18.220', 46 | 'curl_proxy_port' => 0,//8080, 47 | 48 | //=======【上报信息配置】=================================== 49 | /** 50 | * TODO:接口调用上报等级,默认紧错误上报(注意:上报超时间为【1s】,上报无论成败【永不抛出异常】, 51 | * 不会影响接口调用流程),开启上报之后,方便微信监控请求调用的质量,建议至少 52 | * 开启错误上报。 53 | * 上报等级,0.关闭上报, 1.仅错误出错上报, 2.全量上报 54 | * @var int 55 | */ 56 | 'report_levenl' => 1, 57 | ]; 58 | --------------------------------------------------------------------------------