作者 郭文星

123

... ... @@ -230,5 +230,57 @@ class Api extends Controller
//你可以在这里定义你的提示信息,但切记不可在此编写逻辑
$this->success("恭喜你!支付成功!", addon_url("epay/index/index"));
}
/**
* 年检支付成功回调
*/
public function OrderPayNtf()
{
$type = $this->request->param('paytype', 'wechat');
//file_put_contents("pcl_pay_p.log", date("Y-m-d H:i:s") . "::" . json_encode($this->request->param(), JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
$pay = \addons\epay\library\Service::checkNotify($type);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
file_put_contents("pcl_pay_log.log", date("Y-m-d H:i:s") . "::" . json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
$payamount = $type == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
$out_trade_no = $data['out_trade_no'];
//你可以在此编写订单逻辑
//判断是否已更新过支付状态
$cks = Db::name('order')
->where(['order_no' => $data['out_trade_no']])
->find();
if (!empty($cks) && $cks['is_pay'] == '2') {
//更新订单信息
$order['transaction_id'] = $data['transaction_id'];
$order['is_pay'] = 1;
$order['pay_time'] = time();
if ($cks['chejian_site_workers_id'] > 0) {
//$order['status'] = 3;
} else {
$order['status'] = 1;
}
$order['updatetime'] = time();
$rs = Db::name('order')
->where(['order_no' => $data['out_trade_no']])
->update($order);
//生成订单日志
if ($rs != false) {
$orderlog['order_id'] = $cks['id'];
$orderlog['content'] = '订单已支付';
$orderlog['user_id'] = $cks['user_id'];
$orderlog['step'] = 2;
$orderlog['createtime'] = time();
Db::name('order_log')->insertGetId($orderlog);
}
}
//你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
//下面这句必须要执行,且在此之前不能有任何输出
return $pay->success()->send();
}
}
... ...
... ... @@ -2,13 +2,14 @@
namespace app\api\controller;
use app\api\controller\v1\Base;
use app\common\controller\Api;
use think\Db;
/**
* 首页接口
*/
class Car extends Api
class Car extends Base
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
... ... @@ -101,7 +102,7 @@ class Car extends Api
->where(['id' => $this->auth->id])
->field('id,wx_xcx_openid')
->find();
$notifyURI = 'https://wyc.tenyes.cn/addons/epay/api/notifyx/type/wechat';
$notifyURI = $this->doman . '/addons/epay/api/OrderPayNtf';
$params = [
'amount' => $data['price'],
'orderid' => $data['order_no'],
... ... @@ -110,11 +111,8 @@ class Car extends Api
'method' => 'miniapp',
'openid' => $userinfo['wx_xcx_openid'],
];
$f = \addons\epay\library\Service::submitOrder($params);
print_r($f);return;
$this->success("请求成功",$res);
$this->success("请求成功",$f);
}
... ...
... ... @@ -19,6 +19,7 @@ class Base extends Api
{
parent::__construct($request);
$this->qiniuUrl = 'https://qiniu.ask.xp.yn.cn';
$this->doman = 'https://wyc.tenyes.cn/';
$this->AppID = config("site.wxxcx_AppID");//微信小程序AppID
$this->AppSecret = config("site.wxxcx_AppSecret");//微信小程序密钥
}
... ...