[qnbuygroup] VIP用户组插件对接使用xorpay支付的方法?
需要修改的文件:
/addons/qnbuygroup/model/Buygrouporder.php
需要新增的文件:
/addons/xorpay/controller/Buygroup.php
Buygrouporder.php
修改内容如下:
将如下代码注释掉:
//关闭企业支付
/*$epay = get_addon_info('epay');
if ($epay && $epay['state']) {
$notifyurl = $request->root(true) . '/index/qnbuygroup.buygroup/epay/type/notify/paytype/' . $paytype;
$returnurl = $request->root(true) . '/index/qnbuygroup.buygroup/epay/type/return/paytype/' . $paytype;
\addons\epay\library\Service::submitOrder(number_format($money, 2, '.', ''), $order->orderid, $paytype, "购买{$buygroupset['groupname']}", $notifyurl, $returnurl);
exit;
} else {
$result = \think\Hook::listen('qnbuygroup_order_submit', $order);
if (!$result) {
throw new Exception("请先在后台安装并配置微信支付宝整合插件");
}
}*/
在注释的代码下面增加代码:
//使用xorpay 支付
$xorpay = get_addon_info('xorpay');
if ($xorpay && $xorpay['state']) {
$notifyurl = addon_url("xorpay/buygroup/notifyit", [], true, true);
$returnurl = addon_url("xorpay/buygroup/returnit", [], true, true);
//自定义附加传递的信息,例如可以用来传递会员ID、会员账号、商品ID等等
$extend = 'buygroup';//购买用户组
$more = '';
$order_uid = $auth->id;
//发起支付,并跳转到支付页面
\addons\xorpay\library\Service::submitOrder(number_format($money, 2, '.', ''), $order->orderid,"购买{$buygroupset['groupname']}", $paytype, $notifyurl, $returnurl, $extend,$more,$order_uid);
exit;
} else {
$result = \think\Hook::listen('recharge_order_submit', $order);
if (!$result) {
throw new Exception("支付功能不存在或未开启");
}
}
需要新增的Buygroup.php控制器代码如下:
在/addons/xorpay/controller/文件夹新增Buygroup.php
config = get_addon_config('xorpay');
}
public function index()
{
echo 'Is OK!';die;
return $this->view->fetch();
}
/**
* 通知回调
*/
public function notifyit()
{
$aoid = $this->request->request('aoid', '');
$order_id = $this->request->request('order_id', '');
$pay_price = $this->request->request('pay_price', '');
$pay_time = $this->request->request('pay_time', '');
$sign = $this->request->request('sign', '');
$secret = $this->config['app_secret'];
//请求xorpay 的签名 和回调回来的签名方式是不同的
//回调签名方式:签名, 参数 aoid + order_id + pay_price + pay_time + app secret 顺序拼接后 MD5
if ($sign != md5(join('',array($aoid, $order_id, $pay_price, $pay_time, $secret)))) {
$this->error('签名错误');
exit();
}
// 签名验证成功,更新订单数据
try {
$params = [
'paytime'=>strtotime($pay_time),//注意时间要转为时间戳存储
'status'=>'settled',
];
if($aoid)
{
$params['aoid'] = $aoid;
}
//更新xorpay订单
Order::where('out_order_id',$order_id)->update($params);
//更新用户组订单
\addons\qnbuygroup\model\Buygrouporder::settle($order_id, $pay_price);
} catch (Exception $e) {
}
//注意只能输出一个success
echo "success";
return;
}
/**
* 支付成功的返回
*/
public function returnit()
{
$order_id = $this->request->request('order_id', '');
$sign = $this->request->request('sign', '');
$config = get_addon_config('xorpay');
$order = Order::get($order_id);
if(count($order) == 0)
{
$this->error('查询订单失败');
exit();
}
if ($sign != md5(join('',array($order['name'], $order['pay_type'], $order['price'], $order['out_order_id'], $order['notifyurl'], $config['app_secret'])))) {
$this->error('签名错误');
exit();
}
//你可以在这里定义你的提示信息,但切记不可在此编写逻辑
$this->success("恭喜你!购买用户组成功!", url("/index/qnbuygroup.buygrouplog/buylog"));
return;
}
}
发表评论 取消回复