|
@@ -10,15 +10,15 @@ require_once "WxPay.Data.php";
|
|
|
* @author widyhu
|
|
|
*
|
|
|
*/
|
|
|
-class WxPayApi
|
|
|
+class OpenWxPayApi
|
|
|
{
|
|
|
/**
|
|
|
*
|
|
|
* 统一下单,WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayUnifiedOrder $inputObj
|
|
|
+ * @param OpenWxPayUnifiedOrder $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function unifiedOrder($inputObj, $timeOut = 6)
|
|
@@ -26,30 +26,30 @@ class WxPayApi
|
|
|
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsOut_trade_noSet()) {
|
|
|
- throw new WxPayException("缺少统一支付接口必填参数out_trade_no!");
|
|
|
+ throw new OpenWxPayException("缺少统一支付接口必填参数out_trade_no!");
|
|
|
}else if(!$inputObj->IsBodySet()){
|
|
|
- throw new WxPayException("缺少统一支付接口必填参数body!");
|
|
|
+ throw new OpenWxPayException("缺少统一支付接口必填参数body!");
|
|
|
}else if(!$inputObj->IsTotal_feeSet()) {
|
|
|
- throw new WxPayException("缺少统一支付接口必填参数total_fee!");
|
|
|
+ throw new OpenWxPayException("缺少统一支付接口必填参数total_fee!");
|
|
|
}else if(!$inputObj->IsTrade_typeSet()) {
|
|
|
- throw new WxPayException("缺少统一支付接口必填参数trade_type!");
|
|
|
+ throw new OpenWxPayException("缺少统一支付接口必填参数trade_type!");
|
|
|
}
|
|
|
|
|
|
//关联参数
|
|
|
if($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()){
|
|
|
- throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
|
|
|
+ throw new OpenWxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
|
|
|
}
|
|
|
if($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()){
|
|
|
- throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
|
|
|
+ throw new OpenWxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
|
|
|
}
|
|
|
|
|
|
//异步通知url未设置,则使用配置文件中的url
|
|
|
if(!$inputObj->IsNotify_urlSet()){
|
|
|
- $inputObj->SetNotify_url(WxPayConfig::NOTIFY_URL);//异步通知url
|
|
|
+ $inputObj->SetNotify_url(OpenWxPayConfig::NOTIFY_URL);//异步通知url
|
|
|
}
|
|
|
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
|
|
|
//$inputObj->SetSpbill_create_ip("1.1.1.1");
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
@@ -60,7 +60,7 @@ class WxPayApi
|
|
|
|
|
|
$startTimeStamp = self::getMillisecond();//请求开始时间
|
|
|
$response = self::postXmlCurl($xml, $url, false, $timeOut);
|
|
|
- $result = WxPayResults::Init($response);
|
|
|
+ $result = OpenWxPayResults::Init($response);
|
|
|
self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
|
|
|
|
|
|
return $result;
|
|
@@ -70,9 +70,9 @@ class WxPayApi
|
|
|
*
|
|
|
* 查询订单,WxPayOrderQuery中out_trade_no、transaction_id至少填一个
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayOrderQuery $inputObj
|
|
|
+ * @param OpenWxPayOrderQuery $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function orderQuery($inputObj, $timeOut = 6)
|
|
@@ -80,10 +80,10 @@ class WxPayApi
|
|
|
$url = "https://api.mch.weixin.qq.com/pay/orderquery";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
|
|
|
- throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
|
|
|
+ throw new OpenWxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
|
|
|
}
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
|
$inputObj->SetSign();//签名
|
|
@@ -91,7 +91,7 @@ class WxPayApi
|
|
|
|
|
|
$startTimeStamp = self::getMillisecond();//请求开始时间
|
|
|
$response = self::postXmlCurl($xml, $url, false, $timeOut);
|
|
|
- $result = WxPayResults::Init($response);
|
|
|
+ $result = OpenWxPayResults::Init($response);
|
|
|
self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
|
|
|
|
|
|
return $result;
|
|
@@ -101,9 +101,9 @@ class WxPayApi
|
|
|
*
|
|
|
* 关闭订单,WxPayCloseOrder中out_trade_no必填
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayCloseOrder $inputObj
|
|
|
+ * @param OpenWxPayCloseOrder $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function closeOrder($inputObj, $timeOut = 6)
|
|
@@ -111,10 +111,10 @@ class WxPayApi
|
|
|
$url = "https://api.mch.weixin.qq.com/pay/closeorder";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsOut_trade_noSet()) {
|
|
|
- throw new WxPayException("订单查询接口中,out_trade_no必填!");
|
|
|
+ throw new OpenWxPayException("订单查询接口中,out_trade_no必填!");
|
|
|
}
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
|
$inputObj->SetSign();//签名
|
|
@@ -122,7 +122,7 @@ class WxPayApi
|
|
|
|
|
|
$startTimeStamp = self::getMillisecond();//请求开始时间
|
|
|
$response = self::postXmlCurl($xml, $url, false, $timeOut);
|
|
|
- $result = WxPayResults::Init($response);
|
|
|
+ $result = OpenWxPayResults::Init($response);
|
|
|
self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
|
|
|
|
|
|
return $result;
|
|
@@ -133,9 +133,9 @@ class WxPayApi
|
|
|
* 申请退款,WxPayRefund中out_trade_no、transaction_id至少填一个且
|
|
|
* out_refund_no、total_fee、refund_fee、op_user_id为必填参数
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayRefund $inputObj
|
|
|
+ * @param OpenWxPayRefund $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function refund($inputObj, $timeOut = 6)
|
|
@@ -143,25 +143,25 @@ class WxPayApi
|
|
|
$url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
|
|
|
- throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
|
|
|
+ throw new OpenWxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
|
|
|
}else if(!$inputObj->IsOut_refund_noSet()){
|
|
|
- throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!");
|
|
|
+ throw new OpenWxPayException("退款申请接口中,缺少必填参数out_refund_no!");
|
|
|
}else if(!$inputObj->IsTotal_feeSet()){
|
|
|
- throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
|
|
|
+ throw new OpenWxPayException("退款申请接口中,缺少必填参数total_fee!");
|
|
|
}else if(!$inputObj->IsRefund_feeSet()){
|
|
|
- throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
|
|
|
+ throw new OpenWxPayException("退款申请接口中,缺少必填参数refund_fee!");
|
|
|
}else if(!$inputObj->IsOp_user_idSet()){
|
|
|
- throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!");
|
|
|
+ throw new OpenWxPayException("退款申请接口中,缺少必填参数op_user_id!");
|
|
|
}
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
|
$inputObj->SetSign();//签名
|
|
|
$xml = $inputObj->ToXml();
|
|
|
$startTimeStamp = self::getMillisecond();//请求开始时间
|
|
|
$response = self::postXmlCurl($xml, $url, true, $timeOut);
|
|
|
- $result = WxPayResults::Init($response);
|
|
|
+ $result = OpenWxPayResults::Init($response);
|
|
|
self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
|
|
|
|
|
|
return $result;
|
|
@@ -174,9 +174,9 @@ class WxPayApi
|
|
|
* 用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。
|
|
|
* WxPayRefundQuery中out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayRefundQuery $inputObj
|
|
|
+ * @param OpenWxPayRefundQuery $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function refundQuery($inputObj, $timeOut = 6)
|
|
@@ -187,10 +187,10 @@ class WxPayApi
|
|
|
!$inputObj->IsOut_trade_noSet() &&
|
|
|
!$inputObj->IsTransaction_idSet() &&
|
|
|
!$inputObj->IsRefund_idSet()) {
|
|
|
- throw new WxPayException("退款查询接口中,out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个!");
|
|
|
+ throw new OpenWxPayException("退款查询接口中,out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个!");
|
|
|
}
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
|
$inputObj->SetSign();//签名
|
|
@@ -198,7 +198,7 @@ class WxPayApi
|
|
|
|
|
|
$startTimeStamp = self::getMillisecond();//请求开始时间
|
|
|
$response = self::postXmlCurl($xml, $url, false, $timeOut);
|
|
|
- $result = WxPayResults::Init($response);
|
|
|
+ $result = OpenWxPayResults::Init($response);
|
|
|
self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
|
|
|
|
|
|
return $result;
|
|
@@ -207,9 +207,9 @@ class WxPayApi
|
|
|
/**
|
|
|
* 下载对账单,WxPayDownloadBill中bill_date为必填参数
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayDownloadBill $inputObj
|
|
|
+ * @param OpenWxPayDownloadBill $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function downloadBill($inputObj, $timeOut = 6)
|
|
@@ -217,10 +217,10 @@ class WxPayApi
|
|
|
$url = "https://api.mch.weixin.qq.com/pay/downloadbill";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsBill_dateSet()) {
|
|
|
- throw new WxPayException("对账单接口中,缺少必填参数bill_date!");
|
|
|
+ throw new OpenWxPayException("对账单接口中,缺少必填参数bill_date!");
|
|
|
}
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
|
$inputObj->SetSign();//签名
|
|
@@ -247,18 +247,18 @@ class WxPayApi
|
|
|
$url = "https://api.mch.weixin.qq.com/pay/micropay";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsBodySet()) {
|
|
|
- throw new WxPayException("提交被扫支付API接口中,缺少必填参数body!");
|
|
|
+ throw new OpenWxPayException("提交被扫支付API接口中,缺少必填参数body!");
|
|
|
} else if(!$inputObj->IsOut_trade_noSet()) {
|
|
|
- throw new WxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
|
|
|
+ throw new OpenWxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
|
|
|
} else if(!$inputObj->IsTotal_feeSet()) {
|
|
|
- throw new WxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
|
|
|
+ throw new OpenWxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
|
|
|
} else if(!$inputObj->IsAuth_codeSet()) {
|
|
|
- throw new WxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
|
|
|
+ throw new OpenWxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
|
|
|
}
|
|
|
|
|
|
$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
|
$inputObj->SetSign();//签名
|
|
@@ -266,7 +266,7 @@ class WxPayApi
|
|
|
|
|
|
$startTimeStamp = self::getMillisecond();//请求开始时间
|
|
|
$response = self::postXmlCurl($xml, $url, false, $timeOut);
|
|
|
- $result = WxPayResults::Init($response);
|
|
|
+ $result = OpenWxPayResults::Init($response);
|
|
|
self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
|
|
|
|
|
|
return $result;
|
|
@@ -276,20 +276,20 @@ class WxPayApi
|
|
|
*
|
|
|
* 撤销订单API接口,WxPayReverse中参数out_trade_no和transaction_id必须填写一个
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayReverse $inputObj
|
|
|
+ * @param OpenWxPayReverse $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
*/
|
|
|
public static function reverse($inputObj, $timeOut = 6)
|
|
|
{
|
|
|
$url = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
|
|
|
- throw new WxPayException("撤销订单API接口中,参数out_trade_no和transaction_id必须填写一个!");
|
|
|
+ throw new OpenWxPayException("撤销订单API接口中,参数out_trade_no和transaction_id必须填写一个!");
|
|
|
}
|
|
|
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
|
$inputObj->SetSign();//签名
|
|
@@ -297,7 +297,7 @@ class WxPayApi
|
|
|
|
|
|
$startTimeStamp = self::getMillisecond();//请求开始时间
|
|
|
$response = self::postXmlCurl($xml, $url, true, $timeOut);
|
|
|
- $result = WxPayResults::Init($response);
|
|
|
+ $result = OpenWxPayResults::Init($response);
|
|
|
self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
|
|
|
|
|
|
return $result;
|
|
@@ -308,9 +308,9 @@ class WxPayApi
|
|
|
* 测速上报,该方法内部封装在report中,使用时请注意异常流程
|
|
|
* WxPayReport中interface_url、return_code、result_code、user_ip、execute_time_必填
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayReport $inputObj
|
|
|
+ * @param OpenWxPayReport $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function report($inputObj, $timeOut = 1)
|
|
@@ -318,18 +318,18 @@ class WxPayApi
|
|
|
$url = "https://api.mch.weixin.qq.com/payitil/report";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsInterface_urlSet()) {
|
|
|
- throw new WxPayException("接口URL,缺少必填参数interface_url!");
|
|
|
+ throw new OpenWxPayException("接口URL,缺少必填参数interface_url!");
|
|
|
} if(!$inputObj->IsReturn_codeSet()) {
|
|
|
- throw new WxPayException("返回状态码,缺少必填参数return_code!");
|
|
|
+ throw new OpenWxPayException("返回状态码,缺少必填参数return_code!");
|
|
|
} if(!$inputObj->IsResult_codeSet()) {
|
|
|
- throw new WxPayException("业务结果,缺少必填参数result_code!");
|
|
|
+ throw new OpenWxPayException("业务结果,缺少必填参数result_code!");
|
|
|
} if(!$inputObj->IsUser_ipSet()) {
|
|
|
- throw new WxPayException("访问接口IP,缺少必填参数user_ip!");
|
|
|
+ throw new OpenWxPayException("访问接口IP,缺少必填参数user_ip!");
|
|
|
} if(!$inputObj->IsExecute_time_Set()) {
|
|
|
- throw new WxPayException("接口耗时,缺少必填参数execute_time_!");
|
|
|
+ throw new OpenWxPayException("接口耗时,缺少必填参数execute_time_!");
|
|
|
}
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetUser_ip($_SERVER['REMOTE_ADDR']);//终端ip
|
|
|
$inputObj->SetTime(date("YmdHis"));//商户上报时间
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
@@ -346,19 +346,19 @@ class WxPayApi
|
|
|
*
|
|
|
* 生成二维码规则,模式一生成支付二维码
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayBizPayUrl $inputObj
|
|
|
+ * @param OpenWxPayBizPayUrl $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function bizpayurl($inputObj, $timeOut = 6)
|
|
|
{
|
|
|
if(!$inputObj->IsProduct_idSet()){
|
|
|
- throw new WxPayException("生成二维码,缺少必填参数product_id!");
|
|
|
+ throw new OpenWxPayException("生成二维码,缺少必填参数product_id!");
|
|
|
}
|
|
|
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetTime_stamp(time());//时间戳
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
@@ -373,9 +373,9 @@ class WxPayApi
|
|
|
* 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
|
|
|
* 减小二维码数据量,提升扫描速度和精确度。
|
|
|
* appid、mchid、spbill_create_ip、nonce_str不需要填入
|
|
|
- * @param WxPayShortUrl $inputObj
|
|
|
+ * @param OpenWxPayShortUrl $inputObj
|
|
|
* @param int $timeOut
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
* @return 成功时返回,其他抛异常
|
|
|
*/
|
|
|
public static function shorturl($inputObj, $timeOut = 6)
|
|
@@ -383,10 +383,10 @@ class WxPayApi
|
|
|
$url = "https://api.mch.weixin.qq.com/tools/shorturl";
|
|
|
//检测必填参数
|
|
|
if(!$inputObj->IsLong_urlSet()) {
|
|
|
- throw new WxPayException("需要转换的URL,签名用原串,传输需URL encode!");
|
|
|
+ throw new OpenWxPayException("需要转换的URL,签名用原串,传输需URL encode!");
|
|
|
}
|
|
|
- $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
|
|
|
- $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
|
|
|
+ $inputObj->SetAppid(OpenWxPayConfig::APPID);//公众账号ID
|
|
|
+ $inputObj->SetMch_id(OpenWxPayConfig::MCHID);//商户号
|
|
|
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
|
|
|
|
|
|
$inputObj->SetSign();//签名
|
|
@@ -394,7 +394,7 @@ class WxPayApi
|
|
|
|
|
|
$startTimeStamp = self::getMillisecond();//请求开始时间
|
|
|
$response = self::postXmlCurl($xml, $url, false, $timeOut);
|
|
|
- $result = WxPayResults::Init($response);
|
|
|
+ $result = OpenWxPayResults::Init($response);
|
|
|
self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
|
|
|
|
|
|
return $result;
|
|
@@ -414,8 +414,8 @@ class WxPayApi
|
|
|
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
|
|
|
//如果返回成功则验证签名
|
|
|
try {
|
|
|
- $result = WxPayResults::Init($xml);
|
|
|
- } catch (WxPayException $e){
|
|
|
+ $result = OpenWxPayResults::Init($xml);
|
|
|
+ } catch (OpenWxPayException $e){
|
|
|
$msg = $e->errorMessage();
|
|
|
return false;
|
|
|
}
|
|
@@ -458,11 +458,11 @@ class WxPayApi
|
|
|
private static function reportCostTime($url, $startTimeStamp, $data)
|
|
|
{
|
|
|
//如果不需要上报数据
|
|
|
- if(WxPayConfig::REPORT_LEVENL == 0){
|
|
|
+ if(OpenWxPayConfig::REPORT_LEVENL == 0){
|
|
|
return;
|
|
|
}
|
|
|
//如果仅失败上报
|
|
|
- if(WxPayConfig::REPORT_LEVENL == 1 &&
|
|
|
+ if(OpenWxPayConfig::REPORT_LEVENL == 1 &&
|
|
|
array_key_exists("return_code", $data) &&
|
|
|
$data["return_code"] == "SUCCESS" &&
|
|
|
array_key_exists("result_code", $data) &&
|
|
@@ -473,7 +473,7 @@ class WxPayApi
|
|
|
|
|
|
//上报逻辑
|
|
|
$endTimeStamp = self::getMillisecond();
|
|
|
- $objInput = new WxPayReport();
|
|
|
+ $objInput = new OpenWxPayReport();
|
|
|
$objInput->SetInterface_url($url);
|
|
|
$objInput->SetExecute_time_($endTimeStamp - $startTimeStamp);
|
|
|
//返回状态码
|
|
@@ -507,7 +507,7 @@ class WxPayApi
|
|
|
|
|
|
try{
|
|
|
self::report($objInput);
|
|
|
- } catch (WxPayException $e){
|
|
|
+ } catch (OpenWxPayException $e){
|
|
|
//不做任何处理
|
|
|
}
|
|
|
}
|
|
@@ -519,7 +519,7 @@ class WxPayApi
|
|
|
* @param string $url url
|
|
|
* @param bool $useCert 是否需要证书,默认不需要
|
|
|
* @param int $second url执行超时时间,默认30s
|
|
|
- * @throws WxPayException
|
|
|
+ * @throws OpenWxPayException
|
|
|
*/
|
|
|
private static function postXmlCurl($xml, $url, $useCert = false, $second = 30)
|
|
|
{
|
|
@@ -528,10 +528,10 @@ class WxPayApi
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $second);
|
|
|
|
|
|
//如果有配置代理这里就设置代理
|
|
|
- if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
|
|
|
- && WxPayConfig::CURL_PROXY_PORT != 0){
|
|
|
- curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
|
|
|
- curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
|
|
|
+ if(OpenWxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
|
|
|
+ && OpenWxPayConfig::CURL_PROXY_PORT != 0){
|
|
|
+ curl_setopt($ch,CURLOPT_PROXY, OpenWxPayConfig::CURL_PROXY_HOST);
|
|
|
+ curl_setopt($ch,CURLOPT_PROXYPORT, OpenWxPayConfig::CURL_PROXY_PORT);
|
|
|
}
|
|
|
curl_setopt($ch,CURLOPT_URL, $url);
|
|
|
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
|
|
@@ -545,9 +545,9 @@ class WxPayApi
|
|
|
//设置证书
|
|
|
//使用证书:cert 与 key 分别属于两个.pem文件
|
|
|
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
|
|
|
- curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
|
|
|
+ curl_setopt($ch,CURLOPT_SSLCERT, OpenWxPayConfig::SSLCERT_PATH);
|
|
|
curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
|
|
|
- curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
|
|
|
+ curl_setopt($ch,CURLOPT_SSLKEY, OpenWxPayConfig::SSLKEY_PATH);
|
|
|
}
|
|
|
//post提交方式
|
|
|
curl_setopt($ch, CURLOPT_POST, TRUE);
|
|
@@ -561,7 +561,7 @@ class WxPayApi
|
|
|
} else {
|
|
|
$error = curl_errno($ch);
|
|
|
curl_close($ch);
|
|
|
- throw new WxPayException("curl出错,错误码:$error");
|
|
|
+ throw new OpenWxPayException("curl出错,错误码:$error");
|
|
|
}
|
|
|
}
|
|
|
|