NoticeController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace shop\controllers;
  3. use Yii;
  4. use common\components\util;
  5. use common\services\xhPayToolService;
  6. class NoticeController extends PublicController
  7. {
  8. public $categoryList;
  9. //微信支付异步回调
  10. public function actionWxCallback()
  11. {
  12. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  13. if (empty($postStr)) {
  14. util::end();
  15. }
  16. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  17. if ($postObj->return_code != 'SUCCESS') {
  18. Yii::warning('return_code error:' . $postObj->return_code);
  19. util::end();
  20. }
  21. $orderId = $postObj->out_trade_no;
  22. $total_fee = $postObj->total_fee;
  23. $totalFee = $total_fee / 100;
  24. $attach = $postObj->attach;
  25. parse_str($attach);//接收流水类型、代金劵
  26. $couponId = isset($couponId) ? $couponId : 0;
  27. $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
  28. if (isset($capitalType) == false) {
  29. Yii::warning('capitalType empty,orderId:' . $orderId);
  30. util::end();
  31. }
  32. $return = xhPayToolService::weixinPay($orderId, $totalFee, $capitalType, $couponId);//支付回调流程
  33. if ($return['code'] == 'A0002') {
  34. Yii::warning('callback exec and failed,capitalType:' . $capitalType . ' orderId:' . $orderId);
  35. util::end();
  36. }
  37. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  38. }
  39. }