NoticeController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace openend\controllers;
  3. use common\services\xhUserAssetService;
  4. use common\services\xhUserService;
  5. use common\services\xhUserAlipayService;
  6. use common\services\xhMerchantExtendService;
  7. use common\services\xhActiveOrderService;
  8. use common\components\util;
  9. use Yii;
  10. use yii\web\Controller;
  11. use linslin\yii2\curl;
  12. use common\services\xhOrderService;
  13. use common\components\weixinUtil;
  14. use common\components\configDict;
  15. use common\services\xhMerchantService;
  16. use common\services\xhPayToolService;
  17. class NoticeController extends PublicController{
  18. public $cateogryList;
  19. public $enableCsrfValidation = false;
  20. /**
  21. * 微信支付异步回调
  22. */
  23. public function actionApplyWeixinCallback()
  24. {
  25. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  26. if (empty($postStr)) {
  27. util::end();
  28. }
  29. $postObj = simplexml_load_string ($postStr,'SimpleXMLElement',LIBXML_NOCDATA);
  30. if($postObj->return_code != 'SUCCESS'){
  31. Yii::warning('return_code error:'.$postObj->return_code);
  32. util::end();
  33. }
  34. $orderId = $postObj->out_trade_no;
  35. $total_fee = $postObj->total_fee;
  36. $totalFee = $total_fee / 100;
  37. $attach = $postObj->attach;
  38. parse_str($attach);//接收流水类型、代金劵
  39. $couponId = isset($couponId) ? $couponId : 0;
  40. $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
  41. if(isset($capitalType) == false){
  42. Yii::warning('capitalType empty,orderId:'.$orderId);
  43. util::end();
  44. }
  45. $return = xhPayToolService::weixinPay($orderId,$totalFee,$capitalType, $couponId);//支付回调流程
  46. if($return['code'] == 'A0002'){
  47. Yii::warning('callback exec and failed,capitalType:'.$capitalType.' orderId:'.$orderId);
  48. util::end();
  49. }
  50. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  51. }
  52. }