|
|
|
|
@ -10,21 +10,6 @@ class WxMicroPay extends WxPayCommon
|
|
|
|
|
{
|
|
|
|
|
public $pay_url = "https://api.mch.weixin.qq.com/pay/micropay";
|
|
|
|
|
|
|
|
|
|
function checkParameters()
|
|
|
|
|
{
|
|
|
|
|
if (!$this->parameters["out_trade_no"]) {
|
|
|
|
|
throw new Exception("缺少必填参数out_trade_no!" . "<br>");
|
|
|
|
|
} elseif (!$this->parameters["body"]) {
|
|
|
|
|
throw new Exception("缺少必填参数body!" . "<br>");
|
|
|
|
|
} elseif (!$this->parameters["total_fee"]) {
|
|
|
|
|
throw new Exception("缺少必填参数total_fee!" . "<br>");
|
|
|
|
|
} elseif (!$this->parameters["auth_code"]) {
|
|
|
|
|
throw new Exception("缺少必填参数auth_code!" . "<br>");
|
|
|
|
|
} elseif (!strlen($this->parameters["auth_code"]) != 18) {
|
|
|
|
|
throw new Exception("支付码不正确!" . "<br>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* 扫码支付,并且确认结果,接口比较慢
|
|
|
|
|
@ -33,26 +18,38 @@ class WxMicroPay extends WxPayCommon
|
|
|
|
|
public function pay(Recharge $recharge)
|
|
|
|
|
{
|
|
|
|
|
//提交被扫支付
|
|
|
|
|
$this->setParameter("out_trade_no", $recharge->serial);
|
|
|
|
|
$this->setParameter("body", "充值{$recharge->money}元");
|
|
|
|
|
$this->setParameter("total_fee", $recharge->money * 100);
|
|
|
|
|
$this->setParameter("auth_code", request()->auth_code);
|
|
|
|
|
|
|
|
|
|
$this->checkParameters();
|
|
|
|
|
\Log::info($this->parameters);
|
|
|
|
|
$xml = $this->createXml();
|
|
|
|
|
$result = $this->postXmlCurl($xml, $this->pay_url);
|
|
|
|
|
\Log::info($result);
|
|
|
|
|
$result = $this->xmlToArray($result);
|
|
|
|
|
try {
|
|
|
|
|
$this->setParameter("out_trade_no", $recharge->serial);
|
|
|
|
|
$this->setParameter("body", "充值{$recharge->money}元");
|
|
|
|
|
$this->setParameter("total_fee", $recharge->money * 100);
|
|
|
|
|
$this->setParameter("auth_code", request()->auth_code);
|
|
|
|
|
|
|
|
|
|
//如果返回成功
|
|
|
|
|
if (!array_key_exists("return_code", $result) || !array_key_exists("result_code", $result)) {
|
|
|
|
|
throw new Exception("接口调用失败");
|
|
|
|
|
}
|
|
|
|
|
if (!$this->parameters["out_trade_no"]) {
|
|
|
|
|
throw new Exception("缺少必填参数out_trade_no!" . "<br>");
|
|
|
|
|
} elseif (!$this->parameters["body"]) {
|
|
|
|
|
throw new Exception("缺少必填参数body!" . "<br>");
|
|
|
|
|
} elseif (!$this->parameters["total_fee"]) {
|
|
|
|
|
throw new Exception("缺少必填参数total_fee!" . "<br>");
|
|
|
|
|
} elseif (!$this->parameters["auth_code"]) {
|
|
|
|
|
throw new Exception("缺少必填参数auth_code!" . "<br>");
|
|
|
|
|
} elseif (!strlen($this->parameters["auth_code"]) != 18) {
|
|
|
|
|
throw new Exception("支付码不正确!" . "<br>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dd($result);
|
|
|
|
|
\Log::info($this->parameters);
|
|
|
|
|
$xml = $this->createXml();
|
|
|
|
|
$result = $this->postXmlCurl($xml, $this->pay_url);
|
|
|
|
|
\Log::info($result);
|
|
|
|
|
$result = $this->xmlToArray($result);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
//如果返回成功
|
|
|
|
|
if (!array_key_exists("return_code", $result) || !array_key_exists("result_code", $result)) {
|
|
|
|
|
throw new Exception("接口调用失败");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception $exception) {
|
|
|
|
|
return $exception;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//取订单号
|
|
|
|
|
$out_trade_no = $microPayInput->GetOut_trade_no();
|
|
|
|
|
|