123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\AopClient;
- use app\common\library\Common;
- use app\common\model\Config;
- use app\common\model\User;
- use think\Db;
- use think\Request;
- use app\common\model\Order;
- /**
- * 支付成功回调
- */
- class Pay extends Api
- {
- /**
- * 微信支付--商品支付成功回调订单
- */
- public function pay_order(){
- $payXml = file_get_contents("php://input");
- //将xml格式转化为json格式
- $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_NOCDATA));
- //将json格式转成数组格式 $result['out_trade_no']
- $result = json_decode($jsonXml, true);
- if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
- $order = Order::where('status',0)->where('order_no',$result['out_trade_no'])->find();
- if ($order){
- Db::startTrans();
- try {
- $da['pay_time'] = time();
- $da['status'] = 1;
- $da['return_success_info'] = json_encode($result,true);
- Order::where('id',$order['id'])->update($da);
- Common::order_status($order['id'],'微信支付成功');
- Db::commit();
- $arr = array(
- 'return_code' => 'SUCCESS',
- 'return_msg' => 'OK',
- );
- return $this->arrayToXml($arr);
- }catch (Exception $e) {
- Db::rollback();
- file_put_contents("order_pay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND);
- }
- }
- }
- }
- /**
- * 微信支付--加班费支付成功回调订单
- */
- public function overtime_pay_order(){
- $payXml = file_get_contents("php://input");
- //将xml格式转化为json格式
- $jsonXml = json_encode(simplexml_load_string($payXml, 'SimpleXMLElement', LIBXML_NOCDATA));
- //将json格式转成数组格式 $result['out_trade_no']
- $result = json_decode($jsonXml, true);
- if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
- $order = Order::where('overtime_pay_status',1)->where('overtime_pay_order_no',$result['out_trade_no'])->find();
- if ($order){
- Db::startTrans();
- try {
- $da['overtime_pay_time'] = time();
- $da['overtime_pay_status'] = 2;
- $da['overtime_return_success_info'] = json_encode($result,true);
- Order::where('id',$order['id'])->update($da);
- Common::order_status($order['id'],'微信支付加班费成功');
- Db::commit();
- $arr = array(
- 'return_code' => 'SUCCESS',
- 'return_msg' => 'OK',
- );
- return $this->arrayToXml($arr);
- }catch (Exception $e) {
- Db::rollback();
- file_put_contents("order_pay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND);
- }
- }
- }
- }
- /**
- * 支付宝支付--商品支付成功回调订单
- */
- public function alipay_order(){
- $result = input('post.');
- if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
- $order = Order::where('status',0)->where('order_no',$result['out_trade_no'])->find();
- if ($order){
- Db::startTrans();
- try {
- $da['pay_time'] = time();
- $da['status'] = 1;
- $da['return_success_info'] = json_encode($result,true);
- Order::where('id',$order['id'])->update($da);
- Common::order_status($order['id'],'支付宝支付成功');
- Db::commit();
- echo 'success';
- }catch (Exception $e) {
- Db::rollback();
- file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND);
- }
- }
- }
- }
- /**
- * 支付宝支付--商品支付成功回调订单
- */
- public function overtime_alipay_order(){
- $result = input('post.');
- if ($result['trade_status'] == 'TRADE_SUCCESS' || $result['trade_status'] == 'TRADE_FINISHED') {
- $order = Order::where('overtime_pay_status',1)->where('overtime_pay_order_no',$result['out_trade_no'])->find();
- if ($order){
- Db::startTrans();
- try {
- $da['overtime_pay_time'] = time();
- $da['overtime_pay_status'] = 2;
- $da['overtime_return_success_info'] = json_encode($result,true);
- Order::where('id',$order['id'])->update($da);
- Common::order_status($order['id'],'支付宝支付加班费成功');
- Db::commit();
- echo 'success';
- }catch (Exception $e) {
- Db::rollback();
- file_put_contents("order_alipay_error.txt", file_get_contents("php://input") . "\n" . json_encode($result) . "\n" . "\n", FILE_APPEND);
- }
- }
- }
- }
- /**
- * 数组转xml
- * @ApiInternal
- */
- public function arrayToXml($arr)
- {
- $xml = "<xml>";
- foreach ($arr as $key => $val) {
- if (is_numeric($val)) {
- $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
- } else
- $xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
- }
- $xml .= "</xml>";
- return $xml;
- }
- }
|