...
|
...
|
@@ -2,6 +2,7 @@ |
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\admin\model\Order;
|
|
|
use app\common\controller\Api;
|
|
|
use EasyWeChat\Factory;
|
|
|
use think\Validate;
|
...
|
...
|
@@ -31,29 +32,30 @@ class Pay extends Api |
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
*
|
|
|
* @ApiParams (name="openid", type="string", required=true, description="小程序openid")
|
|
|
* @ApiParams (name="pay_order_sn", type="inter", required=true, description="支付订单号")
|
|
|
* @ApiParams (name="order_sn", type="inter", required=true, description="订单号")
|
|
|
*
|
|
|
*/
|
|
|
public function pay(){
|
|
|
if($this->request->isPost()){
|
|
|
$openid = $this->request->post('openid');
|
|
|
$pay_order_sn = $this->request->post('pay_order_sn');
|
|
|
$order_sn = $this->request->post('order_sn');
|
|
|
|
|
|
$rule = config('verify.pay');
|
|
|
$validate = new Validate($rule['rule'],$rule['msg']);
|
|
|
if (!$validate->check(['openid'=>$openid,'pay_order_sn'=>$pay_order_sn])) {
|
|
|
if (!$validate->check(['openid'=>$openid,'order_sn'=>$order_sn])) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
|
|
|
$ffg_host = config('verify.ffg_host');
|
|
|
$status = $this->order_status;
|
|
|
//支付订单
|
|
|
$res = Common::findSoftWhereData('order',['uid'=>$this->uid,'pay_order_sn'=>$pay_order_sn,'status'=>$status[0]],'id,total_price');
|
|
|
$res = Common::findSoftWhereData('order',['uid'=>$this->uid,'order_sn'=>$order_sn,'status'=>$status[0]],'id,total_price');
|
|
|
if(!$res){
|
|
|
$this->error('无效的订单');
|
|
|
}
|
|
|
//创建支付对象
|
|
|
$config = config('verify.wx_pay');
|
|
|
$pay_order_sn = Common::genPayOrderSn('pay');//支付订单号
|
|
|
$app = Factory::payment($config);
|
|
|
$result = $app->order->unify([
|
|
|
'body' => '佛山市理想中网络科技有限公司',
|
...
|
...
|
@@ -73,7 +75,15 @@ class Pay extends Api |
|
|
];
|
|
|
// 注意这里用的是商户平台的Key进行二次签名
|
|
|
$params['paySign'] = generate_sign($params, $config['key']);
|
|
|
$this->success('成功',$params);
|
|
|
|
|
|
//更新订单的支付订单号
|
|
|
$orderModel = new Order();
|
|
|
$res1 = $orderModel->where(['order_sn'=>$order_sn,'uid'=>$this->uid])->update(['pay_order_sn'=>$pay_order_sn]);
|
|
|
if($res1){
|
|
|
$this->success('成功',$params);
|
|
|
}else{
|
|
|
$this->error('失败');
|
|
|
}
|
|
|
}
|
|
|
$this->error($result['err_code_des']);
|
|
|
}else{
|
...
|
...
|
@@ -94,7 +104,9 @@ class Pay extends Api |
|
|
|
|
|
if ($message['result_code'] === 'SUCCESS') {
|
|
|
//支付成功,更新订单状态
|
|
|
|
|
|
$status = $this->order_status;
|
|
|
$orderModel = new Order();
|
|
|
$orderModel->where(['pay_order_sn'=>$message['out_trade_no']])->update(['status'=>$status[1]]);
|
|
|
}elseif($message['result_code'] === 'FAIL') {
|
|
|
//支付失败
|
|
|
}
|
...
|
...
|
@@ -143,42 +155,35 @@ class Pay extends Api |
|
|
$config = config('verify.wx_pay');
|
|
|
$app = Factory::payment($config);
|
|
|
$pay_order_sn = Common::genPayOrderSn('pay');//支付订单号
|
|
|
//写入订单
|
|
|
$res = Common::createOrder($data,$pay_order_sn,$this->uid);
|
|
|
if($res){
|
|
|
$this->success('成功',['order_id'=>$res['order_id']]);
|
|
|
}
|
|
|
$this->error('创建订单失败');
|
|
|
|
|
|
$ffg_host = config('verify.ffg_host');
|
|
|
$result = $app->order->unify([
|
|
|
'body' => '佛山市理想中网络科技有限公司',
|
|
|
'out_trade_no' => $pay_order_sn,//支付订单号
|
|
|
'total_fee' => $data['security_price']*100,//单位分
|
|
|
'notify_url' => $ffg_host.'/api/pay/purchaseNotify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
|
|
|
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
|
|
|
'openid' => $data['openid'],
|
|
|
]);
|
|
|
|
|
|
// $ffg_host = config('verify.ffg_host');
|
|
|
// $result = $app->order->unify([
|
|
|
// 'body' => '佛山市理想中网络科技有限公司',
|
|
|
// 'out_trade_no' => $pay_order_sn,//支付订单号
|
|
|
// 'total_fee' => $data['security_price']*100,//单位分
|
|
|
// 'notify_url' => $ffg_host.'/api/pay/purchaseNotify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
|
|
|
// 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
|
|
|
// 'openid' => $data['openid'],
|
|
|
// ]);
|
|
|
//
|
|
|
// if($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS'){
|
|
|
// $params = [
|
|
|
// 'appId' => $config['app_id'],
|
|
|
// 'timeStamp' => time(),
|
|
|
// 'nonceStr' => $result['nonce_str'], // 统一下单返回的随机字符串
|
|
|
// 'package' => 'prepay_id='.$result['prepay_id'], // 统一下单Id
|
|
|
// 'signType' => 'MD5', // 签名方法
|
|
|
// ];
|
|
|
// // 注意这里用的是商户平台的Key进行二次签名
|
|
|
// $params['paySign'] = generate_sign($params, $config['key']);
|
|
|
// //写入订单
|
|
|
// $res = Common::createOrder($data,$pay_order_sn,$this->uid);
|
|
|
// if($res){
|
|
|
// $this->success('成功',['data'=>$params,'pay_order_sn'=>$pay_order_sn,'order_id'=>$res['order_id']]);
|
|
|
// }
|
|
|
// $this->error('创建订单失败');
|
|
|
// }
|
|
|
// $this->error($result['err_code_des']);
|
|
|
if($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS'){
|
|
|
$params = [
|
|
|
'appId' => $config['app_id'],
|
|
|
'timeStamp' => time(),
|
|
|
'nonceStr' => $result['nonce_str'], // 统一下单返回的随机字符串
|
|
|
'package' => 'prepay_id='.$result['prepay_id'], // 统一下单Id
|
|
|
'signType' => 'MD5', // 签名方法
|
|
|
];
|
|
|
// 注意这里用的是商户平台的Key进行二次签名
|
|
|
$params['paySign'] = generate_sign($params, $config['key']);
|
|
|
//写入订单
|
|
|
$res = Common::createOrder($data,$pay_order_sn,$this->uid);
|
|
|
if($res){
|
|
|
$this->success('成功',$params);
|
|
|
}
|
|
|
$this->error('创建订单失败');
|
|
|
}
|
|
|
$this->error($result['err_code_des']);
|
|
|
}else{
|
|
|
$this->error('请求方式错误');
|
|
|
}
|
...
|
...
|
@@ -196,7 +201,9 @@ class Pay extends Api |
|
|
if ($message['return_code'] === 'SUCCESS') {
|
|
|
if ($message['result_code'] === 'SUCCESS') {
|
|
|
//支付成功
|
|
|
|
|
|
$status = $this->order_status;
|
|
|
$orderModel = new Order();
|
|
|
$orderModel->where(['pay_order_sn'=>$message['out_trade_no']])->update(['status'=>$status[1]]);
|
|
|
}elseif($message['result_code'] === 'FAIL') {
|
|
|
//支付失败,好像有问题
|
|
|
}
|
...
|
...
|
@@ -208,45 +215,4 @@ class Pay extends Api |
|
|
$response->send();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (更新订单号(支付订单失败后调用))
|
|
|
* @ApiSummary (更新订单号(支付订单失败后调用))
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/pay/updateOrder)
|
|
|
* @ApiInternal
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
*
|
|
|
* @ApiParams (name="order_sn", type="inter", required=false, description="支付订单号")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1571812329",
|
|
|
"data": null
|
|
|
})
|
|
|
*/
|
|
|
public function updateOrder(){
|
|
|
if($this->request->isPost()){
|
|
|
$order_sn = $this->request->post('order_sn');
|
|
|
|
|
|
$rule = config('verify.order_sn');
|
|
|
$validate = new Validate($rule['rule'],$rule['msg']);
|
|
|
if (!$validate->check(['order_sn'=>$order_sn])) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
|
|
|
$orderModel = new \app\admin\model\Order();
|
|
|
$pay_order = Common::genPayOrderSn('pay');//支付订单号
|
|
|
$res = $orderModel->where(['order_sn'=>$order_sn,'uid'=>$this->uid])->update(['order_sn'=>$pay_order]);
|
|
|
if($res){
|
|
|
$this->success('成功');
|
|
|
}else{
|
|
|
$this->error('失败');
|
|
|
}
|
|
|
}else{
|
|
|
$this->error('请求方式错误');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|