|
|
|
@ -25,6 +25,149 @@ use EasyWeChat\Factory; |
|
|
|
|
*/ |
|
|
|
|
class Goods extends Controller |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
public function pay(){ |
|
|
|
|
// $merchantCode = '123456789900081'; |
|
|
|
|
// $terminalCode = '00810001'; |
|
|
|
|
// $originalOrderId = '20190306113204000017183219'; |
|
|
|
|
// $data = array( |
|
|
|
|
// 'merchantCode'=>$merchantCode, |
|
|
|
|
// 'terminalCode'=>$terminalCode, |
|
|
|
|
// 'originalOrderId'=>$originalOrderId |
|
|
|
|
// ); |
|
|
|
|
|
|
|
|
|
//$ret = $this->unify(date("YmdHis").mt_rand(1000,9999), "1"); |
|
|
|
|
$ret = $this->tradeQuery(date("YmdHis").mt_rand(1000,9999)); |
|
|
|
|
return $this->renderSuccess([ 'ret' => $ret]); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 支付成功后的异步通知 |
|
|
|
|
* @return bool |
|
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|
|
|
|
*/ |
|
|
|
|
public function notify(): bool |
|
|
|
|
{ |
|
|
|
|
if (!$this->getApp()->notify()) { |
|
|
|
|
$this->setError($this->getApp()->getError()); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 微信支付退款API |
|
|
|
|
* @param string $outTradeNo 第三方交易单号 |
|
|
|
|
* @param string $refundAmount 退款金额 |
|
|
|
|
* @param array $extra 附加数据 (需要携带订单付款总金额) |
|
|
|
|
* @return bool |
|
|
|
|
* @throws BaseException |
|
|
|
|
*/ |
|
|
|
|
public function refund(string $outTradeNo, string $refundAmount, array $extra = []): bool |
|
|
|
|
{ |
|
|
|
|
$tradeQuery_url = "https://test-api-open.chinaums.com/v1/netpay/refund"; |
|
|
|
|
//$order_url = "https://api-mop.chinaums.com/v1/netpay/refund"; |
|
|
|
|
$mid = "898340149000005"; |
|
|
|
|
$tid = "88880001"; |
|
|
|
|
$subAppId = "wxa3127ed5c3542a28"; |
|
|
|
|
$subOpenId = "oxeW66xXaOt4ErNCFTIDn90Zu_FI"; |
|
|
|
|
$params = [ |
|
|
|
|
"requestTimestamp" => date("Y-m-d H:i:s"), |
|
|
|
|
"merOrderId" => $outTradeNo,//date("YmdHis").mt_rand(1000,9999), |
|
|
|
|
"mid" => $mid, |
|
|
|
|
"tid" => $tid, |
|
|
|
|
"targetOrderId" => $tid, |
|
|
|
|
"refundAmount" => $tid, |
|
|
|
|
"refundOrderId" => $tid, |
|
|
|
|
"platformAmount" => $tid, |
|
|
|
|
"refundDesc" => $tid, |
|
|
|
|
]; |
|
|
|
|
$authorization = $this->getAuthorization($params); |
|
|
|
|
$headers = ["Authorization:".$authorization]; |
|
|
|
|
|
|
|
|
|
$ret = httpRequest($order_url, "POST", json_encode($params), $headers, true); |
|
|
|
|
return $ret; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 交易查询 (主动查询订单支付状态) |
|
|
|
|
* @param string $outTradeNo 交易订单号 |
|
|
|
|
* @return array|null |
|
|
|
|
* @throws BaseException |
|
|
|
|
*/ |
|
|
|
|
public function tradeQuery(string $outTradeNo): ?array |
|
|
|
|
{ |
|
|
|
|
$tradeQuery_url = "https://test-api-open.chinaums.com/v1/netpay/query"; |
|
|
|
|
//$order_url = "https://api-mop.chinaums.com/v1/netpay/query"; |
|
|
|
|
$mid = "898340149000005"; |
|
|
|
|
$tid = "88880001"; |
|
|
|
|
$subAppId = "wxa3127ed5c3542a28"; |
|
|
|
|
$subOpenId = "oxeW66xXaOt4ErNCFTIDn90Zu_FI"; |
|
|
|
|
$params = [ |
|
|
|
|
"requestTimestamp" => date("Y-m-d H:i:s"), |
|
|
|
|
"merOrderId" => $outTradeNo,//date("YmdHis").mt_rand(1000,9999), |
|
|
|
|
"mid" => $mid, |
|
|
|
|
"tid" => $tid, |
|
|
|
|
]; |
|
|
|
|
$authorization = $this->getAuthorization($params); |
|
|
|
|
$headers = ["Authorization:".$authorization]; |
|
|
|
|
|
|
|
|
|
$ret = httpRequest($order_url, "POST", json_encode($params), $headers, true); |
|
|
|
|
return $ret; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 统一下单API |
|
|
|
|
* @param string $outTradeNo 交易订单号 |
|
|
|
|
* @param string $totalFee 实际付款金额 |
|
|
|
|
* @param array $extra 附加的数据 (需要携带openid) |
|
|
|
|
* @return bool |
|
|
|
|
* @throws BaseException |
|
|
|
|
*/ |
|
|
|
|
public function unify(string $outTradeNo, string $totalFee, array $extra = []): bool{ |
|
|
|
|
$order_url = "https://test-api-open.chinaums.com/v1/netpay/wx/unified-order"; |
|
|
|
|
//$order_url = "https://api-mop.chinaums.com/v1/netpay/wx/unified-order"; |
|
|
|
|
$mid = "898340149000005"; |
|
|
|
|
$tid = "88880001"; |
|
|
|
|
$subAppId = "wxa3127ed5c3542a28"; |
|
|
|
|
$subOpenId = "oxeW66xXaOt4ErNCFTIDn90Zu_FI"; |
|
|
|
|
$params = [ |
|
|
|
|
"requestTimestamp" => date("Y-m-d H:i:s"), |
|
|
|
|
"merOrderId" => $outTradeNo,//date("YmdHis").mt_rand(1000,9999), |
|
|
|
|
"mid" => $mid, |
|
|
|
|
"tid" => $tid, |
|
|
|
|
"subAppId" => $subAppId, |
|
|
|
|
"subOpenId" => $subOpenId, |
|
|
|
|
"tradeType" => "MINI", |
|
|
|
|
"notifyUrl" => "回调地址", |
|
|
|
|
"orderDesc" => "账单描述", |
|
|
|
|
"totalAmount" => $totalFee, |
|
|
|
|
"divisionFlag" => true,//分账标记 |
|
|
|
|
"platformAmount" => true,//平台商户分 账金额 |
|
|
|
|
"subOrders" => [ |
|
|
|
|
[ |
|
|
|
|
"mid" => "111", |
|
|
|
|
"totalAmount" => 1, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
$authorization = $this->getAuthorization($params); |
|
|
|
|
$headers = ["Authorization:".$authorization]; |
|
|
|
|
|
|
|
|
|
$ret = httpRequest($order_url, "POST", json_encode($params), $headers, true); |
|
|
|
|
return $ret; |
|
|
|
|
} |
|
|
|
|
public function getAuthorization($data){ |
|
|
|
|
$appid = 'f0ec96ad2c3848b5b810e7aadf369e2f'; |
|
|
|
|
$appkey = '775481e2556e4564985f5439a5e6a277'; |
|
|
|
|
|
|
|
|
|
$timestamp = date("YmdHis",time()); |
|
|
|
|
$nonce = md5(uniqid((string)microtime(true),true)); |
|
|
|
|
$body = json_encode($data); |
|
|
|
|
//echo $body; |
|
|
|
|
$str = bin2hex(hash('sha256', $body, true)); |
|
|
|
|
$signature = base64_encode(hash_hmac('sha256', "$appid$timestamp$nonce$str", $appkey, true)); |
|
|
|
|
$authorization = "OPEN-BODY-SIG AppId=$appid, Timestamp=$timestamp, Nonce=$nonce, =$signature"; |
|
|
|
|
|
|
|
|
|
return $authorization; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 商品列表 |
|
|
|
|
* @return Json |
|
|
|
|