NoticeController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace open\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. /**
  20. * 微信支付异步回调
  21. */
  22. public function actionApplyWeixinCallback()
  23. {
  24. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  25. if (empty($postStr)) {
  26. util::end();
  27. }
  28. $postObj = simplexml_load_string ($postStr,'SimpleXMLElement',LIBXML_NOCDATA);
  29. if($postObj->return_code != 'SUCCESS'){
  30. Yii::warning('return_code error:'.$postObj->return_code);
  31. util::end();
  32. }
  33. $orderId = $postObj->out_trade_no;
  34. $total_fee = $postObj->total_fee;
  35. $totalFee = $total_fee / 100;
  36. $attach = $postObj->attach;
  37. parse_str($attach);//接收流水类型、代金劵
  38. $couponId = isset($couponId) ? $couponId : 0;
  39. $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
  40. if(isset($capitalType) == false){
  41. Yii::warning('capitalType empty,orderId:'.$orderId);
  42. util::end();
  43. }
  44. $return = xhPayToolService::weixinPay($orderId,$totalFee,$capitalType, $couponId);//支付回调流程
  45. if($return['code'] == 'A0002'){
  46. Yii::warning('callback exec and failed,capitalType:'.$capitalType.' orderId:'.$orderId);
  47. util::end();
  48. }
  49. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  50. }
  51. }