NoticeController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. //接收流水类型、代金劵
  26. parse_str($attach);
  27. $couponId = isset($couponId) ? $couponId : 0;
  28. //流水类型
  29. $capitalType = isset($capitalType) ? $capitalType : null;
  30. $wxPayType = isset($wxPayType) ? $wxPayType : 0;
  31. if (isset($capitalType) == false) {
  32. Yii::warning('capitalType empty,orderId:' . $orderId);
  33. util::end();
  34. }
  35. $callbackParams = ['wxPayType' => $wxPayType];
  36. $return = xhPayToolService::weixinPay($callbackParams, $orderId, $totalFee, $capitalType, $couponId);//支付回调流程
  37. if ($return['code'] == 'A0002') {
  38. Yii::warning('callback exec and failed,capitalType:' . $capitalType . ' orderId:' . $orderId);
  39. util::end();
  40. }
  41. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  42. }
  43. }