NoticeController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace mini\controllers;
  3. use common\services\xhPayToolService;
  4. use Yii;
  5. use yii\web\Controller;
  6. use common\components\util;
  7. use common\services\xhRechargeService;
  8. class NoticeController extends Controller
  9. {
  10. public $enableCsrfValidation = false;
  11. /**
  12. * 微信支付异步回调
  13. */
  14. public function actionWeixinRechargeCallback()
  15. {
  16. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  17. if (empty($postStr)) {
  18. util::end();
  19. }
  20. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  21. if ($postObj->return_code != 'SUCCESS') {
  22. Yii::warning('return_code error:' . $postObj->return_code);
  23. util::end();
  24. }
  25. $orderId = $postObj->out_trade_no;
  26. Yii::info('recharge order id:' . $orderId);
  27. $total_fee = $postObj->total_fee;
  28. $totalFee = $total_fee / 100;
  29. $attach = $postObj->attach;
  30. parse_str($attach);//接收流水类型、代金劵
  31. $couponId = isset($couponId) ? $couponId : 0;
  32. $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
  33. if (isset($capitalType) == false) {
  34. Yii::warning('capitalType empty,orderId:' . $orderId);
  35. util::end();
  36. }
  37. $recharge = xhRechargeService::getById($orderId);
  38. if (empty($recharge)) {
  39. Yii::warning('recharge order empty');
  40. util::end();
  41. }
  42. $return = xhRechargeService::miniRecharge($orderId, $totalFee);
  43. if ($return['status'] == false) {
  44. Yii::warning($return['msg']);
  45. util::end();
  46. }
  47. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  48. }
  49. public function actionMiniPayCallback()
  50. {
  51. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  52. if (empty($postStr)) {
  53. util::end();
  54. }
  55. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  56. if ($postObj->return_code != 'SUCCESS') {
  57. Yii::warning('return_code error:' . $postObj->return_code);
  58. util::end();
  59. }
  60. $orderId = $postObj->out_trade_no;
  61. $total_fee = $postObj->total_fee;
  62. $totalFee = $total_fee / 100;
  63. $attach = $postObj->attach;
  64. parse_str($attach);//接收流水类型、代金劵
  65. $couponId = isset($couponId) ? $couponId : 0;
  66. $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
  67. if (isset($capitalType) == false) {
  68. Yii::warning('capitalType empty,orderId:' . $orderId);
  69. util::end();
  70. }
  71. $return = xhPayToolService::weixinPay($orderId, $totalFee, $capitalType, $couponId);//支付回调流程
  72. if ($return['code'] == 'A0002') {
  73. Yii::warning('callback exec and failed,capitalType:' . $capitalType . ' orderId:' . $orderId);
  74. util::end();
  75. }
  76. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  77. }
  78. }