Commit daec9f86 authored by 蔡闯's avatar 蔡闯

支付异步回调

parent 75a10dbf
......@@ -15,8 +15,9 @@ class Payorder extends Base
//获取是业主身份的房间
$vacancys = Db::name('house_user_bind')->alias('hub')
->rightJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->rightJoin('house_village hvi','hvi.village_id = hv.village_id')
->where(['hub.type'=>0,'hub.status'=>1])
->field('hub.house_user_bind_id,hv.vacancy_id,hv.vacancy_code,hv.layout_id')
->field('hub.house_user_bind_id,hv.vacancy_id,hv.vacancy_code,hv.layout_id,hvi.village_name')
->select()->toArray();
if($vacancys) {
$convertArr = $this->convertArr;
......@@ -195,20 +196,18 @@ class Payorder extends Base
public function createOrder(){
$vacancy_id = Request::param('vacancy_id');
$bind_id = Request::param('bind_id');
$all_cost_arr = Request::param('cost_ids');
foreach ($all_cost_arr as $k => $v) {
$cost_ids = Request::param('cost_ids');
//验证物业费订单是否是连续的
$where['type'] = 'property';
$where['is_pay'] = 0;
$where['vacancy_id'] = $v['vacancy_id'];
$where['vacancy_id'] = $vacancy_id;
$property_cost_ids = Db::name('cost')->where($where)->whereIn('cost_id',$cost_ids)->column('cost_id'); //上传的未缴物业费的连续cost_id
$limit = count($property_cost_ids);
$cost_property_ids = Db::name('cost')->where($where)->limit($limit)->column('cost_id');
if($cost_property_ids != $property_cost_ids) {
return $this->returnJson([],'物业费缴费必须连续!');
}
}
$total_money = Request::param('total_money',0);
//判断金额是否一致
......@@ -252,9 +251,7 @@ class Payorder extends Base
//根据房间id获取当前的物业id和小区id
public function getProperty($vacancy_id) {
$data = Db::name('house_vacancy')->alias('hv')->leftJoin('house_village hvi','hvi.village_id = hv.village_id')->where(['hv.vacancy_id'=>$vacancy_id])->field('hvi.village_id,hvi.property_id')->find();
if($data){
return ['code'=>200,'data'=>$data];
} else {
......@@ -279,6 +276,8 @@ class Payorder extends Base
$param['subject'] = $orderInfo['order_name'];
$param['total_amount'] = floatval($orderInfo['money']);
$res= $this->getAliPaySign($param);
Db::name('pay_order')->where(['order_id'=>$order_id])->save(['pay_type'=>"支付宝"]);
//微信支付
} else {
$param['order_id'] = $orderInfo['order_id'];
......@@ -286,6 +285,8 @@ class Payorder extends Base
$param['order_name'] = $orderInfo['order_name'];
$param['order_num'] = $orderInfo['order_num'];
$res= $this->getWeiXinPaySign($param);
//更改订单的支付方式
Db::name('pay_order')->where(['order_id'=>$order_id])->save(['pay_type'=>"微信"]);
}
return $this->returnJson($res);
} else {
......@@ -299,14 +300,14 @@ class Payorder extends Base
require_once "../extend/aliPay/AopClient.php";
require_once "../extend/aliPay/request/AlipayTradeAppPayRequest.php";
$aop = new \AopClient();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
// $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
// $aop->apiVersion = '1.0';
// $aop->postCharset = 'utf-8';
// $aop->format = 'json';
$aop->appId = config('app.pay_alipay_appid');
$aop->rsaPrivateKey = config('app.pay_alipay_merchant_private_key');
$aop->alipayrsaPublicKey = config('app.pay_alipay_public_key');
$aop->apiVersion = '1.0';
$aop->signType = config('app.pay_alipay_sign_type');
$aop->postCharset = 'utf-8';
$aop->format = 'json';
$request = new \AlipayTradeAppPayRequest();
$request->setNotifyUrl(config('app.notifyurl'));
$request->setBizContent(json_encode($param));
......@@ -322,7 +323,6 @@ class Payorder extends Base
$configArr['notifyurl'] = config('app.notifyurl');
$weixin = new \Weixin($param,$configArr);
return $weixin->pay();
}
//检查订单是否合法
......
......@@ -5,11 +5,73 @@ namespace app\api\controller;
use app\BaseController;
use think\facade\Db;
class Payreturn extends BaseController
{
//支付成功后的异步通知地址
public function payReturn() {
//支付宝支付成功后的异步通知地址
public function aliPayReturn() {
require_once "../extend/aliPay/AopClient.php";
//生成日志
$this->createPayLog($_POST,"支付宝");
$aop = new \AopClient();
$public_key = config('app.pay_alipay_public_key');
$aop->alipayrsaPublicKey = $public_key;
$flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");
if($flag){
if($this->changePayStatus($_POST['out_trade_no'])){
die('success');
}
}
die('fail');
}
//微信 值后的异步通知地址
public function weiXinPayReturn(){
$testxml = file_get_contents("php://input");
$jsonxml = json_encode(simplexml_load_string($testxml, 'SimpleXMLElement', LIBXML_NOCDATA));
$result = json_decode($jsonxml, true);
$this->createPayLog($result,"微信");
if($result){
//如果成功返回了
if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
if($this->changePayStatus($result['out_trade_no'])){
die("<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
</xml>");
}
}
}
}
//根据获取到的订单id,更改状态
private function changePayStatus($out_trade_no) {
$where['order_num'] = $out_trade_no;
$save['pay_time'] = time();
$save['paid'] = 1;
$cost_ids = DB::name('pay_order')->where(['order_num'=>$out_trade_no])->value('cost_ids');
$cost_ids_arr = json_decode($cost_ids);
Db::startTrans();
try{
Db::name('pay_order')->where($where)->save($save);
Db::name('cost')->where('cost_id','in',$cost_ids_arr)->save($save);
Db::commit();
return true;
}catch(\Exception $e){
Db::rollback();
return false;
}
}
public function createPayLog($data,$type){
$save['create_time'] = time();
$save['data'] = json_encode($data);
$save['type'] = $type;
$save['out_trade_no'] = $data['out_trade_no'];
Db::name('pay_log')->insert($save);
}
}
\ No newline at end of file
......@@ -52,17 +52,19 @@ return [
'public_key'=>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvrbXi8/ePxzFfIOcF5flf/YILuW0q7OVt+9jHZoSn/dkY6J7mYNate4tYq+QhPtBm7dKDu9WqF9nTKnwgoDBdZdDwudANDYNxBLS+Wpa03l/FpgJCSGe6ZAfb9EXKbOpkYMyKqWpFPF1261vwb0xYRgMZGeGXphGHTaXpFyHj9hR0WxAxHQVGFJeJP4S3SswI7klK9ASd2a1PzGad2XVT/MQUseNMKsHl32tklhU/qjLYsmOJb4w79gySKDC85mFAgL6KyVVKW0juroIRb1IxLUYEBUwChzQf3r+0TJ6fJ9yGh19lKS5pS4Hr/AZbA5wX+PBMe7H4nODlGGkPXhUCwIDAQAB',
//支付宝公钥
'pay_alipay_public_key'=>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtl27/bcRervEf1YJoSGyQusBAh9CtcwyzZzUBfHtclYUDQZ154SijHfNxWX71AtMgPnTdeSzFC6Ky6WC9/MSAz2OrSbhhi7PX+f+ydgnBL/CoPw5O699MHuCTQzuOKRVoEwLcgjWm3nJNELTY9RVGQ2GkAD+Tj4wih2FXoFmVyGMdoz8dsYFBo/fgxOhb+mkYVy+uJfu4vuh7DwM2T9H5z8PmodDLvPnqO1+IEqFvoSdBf4Hyy0SNaurrWrsBDPO1ei41yD2tGxwHSCMN2NvChAnyHMblzdU2OvIjnaJrNeEeD/lBmWJs2Z/I2NHkjO/zcWShIldf8UTl64vJfGQbwIDAQAB',
//支付宝支付回调
'notifyurl' =>'http://'.$_SERVER['SERVER_NAME'].'/api/PayReturn/aliPayReturn',
//微信app支付参数
'weixinPay' => [
'pay_weixin_appid'=>'wx8dbf4b4b823f34e7',
'pay_weixin_mchid'=>'1586820961',
'pay_weixin_appsecret'=>'5eb1fb7502cc2b24be7b67e9fe04870c',
'pay_weixin_key'=>'41914f15f59dc19fef30385f46eb4ce4',
'notifyurl' =>'http://'.$_SERVER['SERVER_NAME'].'/api/PayReturn/weiXinPayReturn',
],
//异步通知地址
'notifyurl' =>'http://ruer.com/api/PayReturn/payReturn',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment