| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace mini\controllers;
- use common\services\xhPayToolService;
- use Yii;
- use yii\web\Controller;
- use common\components\util;
- use common\services\xhRechargeService;
- class NoticeController extends Controller
- {
-
- public $enableCsrfValidation = false;
-
- /**
- * 微信支付异步回调
- */
- public function actionWeixinRechargeCallback()
- {
- $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
- if (empty($postStr)) {
- util::end();
- }
- $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- if ($postObj->return_code != 'SUCCESS') {
- Yii::warning('return_code error:' . $postObj->return_code);
- util::end();
- }
- $orderId = $postObj->out_trade_no;
- Yii::info('recharge order id:' . $orderId);
- $total_fee = $postObj->total_fee;
- $totalFee = $total_fee / 100;
- $attach = $postObj->attach;
- parse_str($attach);//接收流水类型、代金劵
- $couponId = isset($couponId) ? $couponId : 0;
- $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
- if (isset($capitalType) == false) {
- Yii::warning('capitalType empty,orderId:' . $orderId);
- util::end();
- }
- $recharge = xhRechargeService::getById($orderId);
- if (empty($recharge)) {
- Yii::warning('recharge order empty');
- util::end();
- }
- $return = xhRechargeService::miniRecharge($orderId, $totalFee);
- if ($return['status'] == false) {
- Yii::warning($return['msg']);
- util::end();
- }
- echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
- }
-
- public function actionMiniPayCallback()
- {
- $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
- if (empty($postStr)) {
- util::end();
- }
- $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- if ($postObj->return_code != 'SUCCESS') {
- Yii::warning('return_code error:' . $postObj->return_code);
- util::end();
- }
- $orderId = $postObj->out_trade_no;
- $total_fee = $postObj->total_fee;
- $totalFee = $total_fee / 100;
- $attach = $postObj->attach;
- parse_str($attach);//接收流水类型、代金劵
- $couponId = isset($couponId) ? $couponId : 0;
- $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
- if (isset($capitalType) == false) {
- Yii::warning('capitalType empty,orderId:' . $orderId);
- util::end();
- }
- $return = xhPayToolService::weixinPay($orderId, $totalFee, $capitalType, $couponId);//支付回调流程
- if ($return['code'] == 'A0002') {
- Yii::warning('callback exec and failed,capitalType:' . $capitalType . ' orderId:' . $orderId);
- util::end();
- }
- echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
- }
-
- }
|