您好,请问Xorpay插件支持部署在香港服务器的网站吗?
我用同样的网站程序,部署在大陆服务器时,余额充值和文章付费阅读测试都能成功,回调也正常,支付后显示成功字样,可是把程序放到香港服务器上后能支付成功,按F12查看也有监听,可是画面就一直停在支付页面,只有刷新后就会提示“订单已支付”。
下面是代码,请您看看。
/addons/xorpay/controller/Cms.php的代码:
<?php
namespace addons\xorpay\controller;
use addons\xorpay\model\Order;
use think\addons\Controller;
/**
* 文章支付处理类
*
* Class Index
* @package addons\xorpay\controller
*/
class Cms extends Controller
{
protected $layout = 'default';
protected $config = [];
public function _initialize()
{
parent::_initialize();
$this->config = get_addon_config('xorpay');
}
public function index()
{
echo 'Is OK!';die;
}
/**
* 通知回调
*/
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'=>$pay_time,
'status'=>'settled',
];
if($aoid)
{
$params['aoid'] = $aoid;
}
Order::where('out_order_id',$order_id)->update($params);
//更新CMS 订单
\addons\cms\model\Order::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((array)$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();
}
$order = \addons\cms\model\Order::getByOrderid($order['out_order_id']);
if (!$order->archives) {
$this->error('未找到文档信息!');
}
//你可以在这里定义你的提示信息,但切记不可在此编写逻辑
$this->redirect($order->archives->url);
return;
}
}
这个是/addons/cms/model/Order.php的代码:
<?php
namespace addons\cms\model;
use addons\cms\library\OrderException;
use addons\epay\library\Service;
use app\common\library\Auth;
use app\common\model\User;
use think\Exception;
use think\Model;
use think\Request;
/**
* 订单模型
*/
class Order extends Model
{
protected $name = "cms_order";
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
protected static $config = [];
protected static function init()
{
$config = get_addon_config('cms');
self::$config = $config;
}
/**
* 获取查询条件
* @return \Closure
*/
protected static function getQueryCondition()
{
$condition = function ($query) {
$auth = Auth::instance();
$user_id = $auth->isLogin() ? $auth->id : 0;
$ip = Request::instance()->ip(0, false);
$config = get_addon_config('cms');
//如果开启支付需要登录,则只判断user_id
if ($config['ispaylogin']) {
$query->where('user_id', $user_id);
} else {
if ($user_id) {
$query->whereOr('user_id', $user_id)->whereOr('ip', $ip);
} else {
$query->where('user_id', 0)->where('ip', $ip);
}
}
};
return $condition;
}
/**
* 检查订单
* @param int $id 订单号
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function checkOrder($id)
{
$archives = Archives::get($id);
if (!$archives) {
return false;
}
$where = [
'archives_id' => $id,
'status' => 'paid',
];
//匹配已支付订单
$order = self::where($where)->where(self::getQueryCondition())->order('id', 'desc')->find();
return $order ? true : false;
}
/**
* 发起订单支付
* @param int $id 文档ID
* @param string $paytype 支付方式
* @param string $openid 微信openid
* @param null $method 支付方式
* @return mixed|string
* @throws OrderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function submitOrder($id, $paytype = 'alipay', $openid = '', $method = null)
{
$archives = Archives::get($id);
if (!$archives) {
throw new OrderException('文档未找到');
}
$order = Order::where('archives_id', $archives['id'])
->where(self::getQueryCondition())
->order('id', 'desc')
->find();
if ($order && $order['status'] == 'paid') {
throw new OrderException('订单已支付');
}
$auth = Auth::instance();
$request = Request::instance();
if (!$order || (time() - $order->createtime) > 600 || $order->amount != $archives->price) {
$orderid = date("YmdHis") . mt_rand(100000, 999999);
$data = [
'user_id' => $auth->id ? $auth->id : 0,
'orderid' => $orderid,
'archives_id' => $archives->id,
'title' => "付费阅读",
'amount' => $archives->price,
'payamount' => 0,
'paytype' => $paytype,
'ip' => $request->ip(0, false),
'useragent' => substr($request->server('HTTP_USER_AGENT'), 0, 255),
'status' => 'created'
];
$order = Order::create($data);
} else {
if ($order->amount != $archives->price) {
$order->amount = $archives->price;
$order->save();
}
}
//使用余额支付
if ($paytype == 'balance') {
if (!$auth->id) {
throw new OrderException('需要登录后才能够支付');
}
if ($auth->money < $archives->price) {
throw new OrderException('余额不足,无法进行支付');
}
\think\Db::startTrans();
try {
User::money(-$archives->price, $auth->id, '购买付费文档:' . $archives['title']);
self::settle($order->orderid);
\think\Db::commit();
} catch (Exception $e) {
\think\Db::rollback();
throw new OrderException($e->getMessage());
}
throw new OrderException('余额支付成功', 1);
}
//使用xorpay 支付
$xorpay = get_addon_info('xorpay');
if ($xorpay && $xorpay['state']) {
$notifyurl = addon_url("xorpay/cms/notifyit", [], true, true);
$returnurl = addon_url("xorpay/cms/returnit", [], true, true);
//自定义附加传递的信息,例如可以用来传递会员ID、会员账号、商品ID等等
$extend = 'article';//充值类型
$more = $order->archives_id;//文章ID
$order_uid = $auth->id;
//发起支付,并跳转到支付页面
\addons\xorpay\library\Service::submitOrder($order->amount, $order->orderid,'购买使用权限-云友论坛', $paytype, $notifyurl, $returnurl, $extend,$more,$order_uid);
exit;
} else {
$result = \think\Hook::listen('recharge_order_submit', $order);
if (!$result) {
throw new Exception("支付功能不存在或未开启");
}
}
}
/**
* 订单结算
* @param int $orderid 订单号
* @param float $payamount 支付金额
* @param string $memo 备注信息
* @return bool
* @throws \think\exception\DbException
*/
public static function settle($orderid, $payamount = null, $memo = '')
{
$order = Order::getByOrderid($orderid);
if (!$order) {
return false;
}
if ($order['status'] != 'paid') {
$payamount = $payamount ? $payamount : $order->amount;
//计算收益
$config = get_addon_config('cms');
list($systemRatio, $userRatio) = explode(':', $config['archivesratio']);
User::money($systemRatio * $payamount, $config['system_user_id'], '付费文章收益');
User::money($userRatio * $payamount, $order->archives->user_id, '付费文章收益');
$order->payamount = $payamount;
$order->paytime = time();
$order->status = 'paid';
$order->memo = $memo;
$order->save();
}
return true;
}
public function archives()
{
return $this->belongsTo('Archives', 'archives_id', 'id');
}
}
请您帮忙看一下,谢谢!
您好,我换到了香港服务器,经过查看数据库前缀这些并有没有变,而且订单已经成功生成,控制台也没有报错。
下面一张是我的xorpay插件配置:
请看一下。
补充一点:大陆服务器ip可以正常收到回调结果,现在这个47.是香港的就不可以了,
你把域名绑上试试,刷新会提示订单已支付说明是已经回调过了,只是定时查询订单这块没查到。
问题还是依旧的话,把项目链接发给我我帮你检查一下!
@jianbs 前辈,我试过了,问题还在的,我把链接1发给您,网址:www.yunyoucc.com
@wanna 来来来 远程给你看下一下,QQ号私信发给你了,你加一下,应该是你的支付成功的回调方法里哪个位置报错了!