97 lines
4.4 KiB
PHP
97 lines
4.4 KiB
PHP
<?php
|
||
|
||
|
||
namespace app\common\pay;
|
||
|
||
|
||
use app\common\traits\ReturnTrait;
|
||
use app\common\yun\Base;
|
||
use app\common\yun\Config;
|
||
use app\common\yun\Router;
|
||
use app\common\yun\service\BaseService;
|
||
use think\Route;
|
||
|
||
class YunPay
|
||
{
|
||
use ReturnTrait;
|
||
public $order_id;
|
||
public $real_name;
|
||
public $id_card;
|
||
public $card_no;
|
||
public $order_amount;
|
||
// public $notify_url = 'http://ceshi.limaoyuyin.cn/api/pay_notify/yun_notify';
|
||
public $notify_url = 'http://hmr.qixing2.top:621/api/pay_notify/yun_notify';
|
||
|
||
public $phone = '';
|
||
public $config;
|
||
public $remark = '';
|
||
public function __construct($order_id, $real_name, $id_card, $card_no, $order_amount, $phone = '')
|
||
{
|
||
$this->order_id = $order_id;
|
||
$this->real_name = $real_name;
|
||
$this->id_card = $id_card;
|
||
$this->card_no = $card_no;
|
||
$this->phone = $phone;
|
||
$this->order_amount = $order_amount;
|
||
$this->config = Conf::config();
|
||
}
|
||
private function deal_params($api_url)
|
||
{
|
||
$base = new Base($api_url, 'post');
|
||
$base->addParam("order_id", $this->order_id); # 商户订单号,由商户保持唯⼀性(必填),64个英⽂字符以内
|
||
$base->addParam("dealer_id", $this->config->dealer_id); # 商户代码(必填)
|
||
$base->addParam("broker_id", $this->config->broker_id); # 综合服务主体ID(必填)
|
||
$base->addParam("real_name", $this->real_name); # 银⾏开户姓名(必填)
|
||
$base->addParam("id_card", $this->id_card); # 身份证(必填)
|
||
$base->addParam("card_no", $this->card_no); # 银行卡号,只支持对私借记卡(必填)
|
||
$base->addParam("phone_no", $this->phone); # ⼿机号(选填)
|
||
$base->addParam("pay", $this->order_amount); # 订单⾦额(参数类型是string类型,单位为元,支持两位小数,必填)
|
||
$base->addParam("pay_remark", $this->remark); # 订单备注( 选填,最⼤20个字符,⼀个汉字占2个字符,不允许特殊字符:不支持特殊字符 ' " & | @% ( ) - : # + / < > ¥ \ ,
|
||
$base->addParam("notify_url", $this->notify_url); # 回调地址(选填,最⼤⻓度为200)
|
||
return $base;
|
||
}
|
||
public function bank()
|
||
{
|
||
$api_url = Router::BANK_CARD;
|
||
$base = $this->deal_params($api_url);
|
||
$GoPay = new BaseService($this->config, $base);
|
||
$bankPay = $GoPay->request();
|
||
if ($bankPay['code'] == '0000') {
|
||
// 订单接收成功,支付结果未知,待异步通知
|
||
// TODO 等待异步通知或订单查询接口获取订单状态
|
||
return self::rep_success_format('接单成功');
|
||
} else
|
||
if ($bankPay['code'] == '2002') {
|
||
// 已上传过该流水
|
||
// TODO 幂等性校验,订单号已存在,具体订单结果需等待异步通知,或主动调用订单查询接口获取
|
||
// echo "订单已存在";
|
||
return self::rep_fail_format('订单已存在');
|
||
}
|
||
else
|
||
// TODO 根据返回的message处理订单请求,切记若需重试请求,请使用原订单号重试
|
||
// echo $bankPay['message'];
|
||
return self::rep_fail_format($bankPay['message']);
|
||
}
|
||
public function alipay()
|
||
{
|
||
$api_url = Router::ALI_PAY;
|
||
$base = $this->deal_params($api_url);
|
||
$GoPay = new BaseService($this->config, $base);
|
||
$bankPay = $GoPay->request();
|
||
if ($bankPay['code'] == '0000') {
|
||
// 订单接收成功,支付结果未知,待异步通知
|
||
// TODO 等待异步通知或订单查询接口获取订单状态
|
||
return self::rep_success_format('接单成功');
|
||
} else
|
||
if ($bankPay['code'] == '2002') {
|
||
// 已上传过该流水
|
||
// TODO 幂等性校验,订单号已存在,具体订单结果需等待异步通知,或主动调用订单查询接口获取
|
||
// echo "订单已存在";
|
||
return self::rep_fail_format('订单已存在');
|
||
}
|
||
else
|
||
// TODO 根据返回的message处理订单请求,切记若需重试请求,请使用原订单号重试
|
||
// echo $bankPay['message'];
|
||
return self::rep_fail_format($bankPay['message']);
|
||
}
|
||
} |