PayController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace backend\modules\user\controllers;
  3. use backend\models\forms\PayForm;
  4. use Yii;
  5. use yii\web\BadRequestHttpException;
  6. class PayController extends BaseController
  7. {
  8. /**
  9. * @return \yii\web\Response
  10. * @throws \Exception
  11. */
  12. public function actionOutpay()
  13. {
  14. $model = new PayForm();
  15. if (Yii::$app->getRequest()->getIsPost()) {
  16. $data = Yii::$app->getRequest()->post();
  17. $payMethod = isset($data['payMethod']) ? trim($data['payMethod']) : '';
  18. $data['payType'] = $model->getPayTypeByMethod($payMethod);
  19. if ($data['payType'] == 1) {
  20. $data['bankCode'] = isset($data['huanqiuBankCode']) ? trim($data['huanqiuBankCode']) : '';
  21. }
  22. if ($data['payType'] == 2) {
  23. $data['bankCode'] = isset($data['payflashBankCode']) ? trim($data['payflashBankCode']) : ''; //支付方式
  24. }
  25. if ($data['payType'] == 4) {
  26. $data['bankCode'] = isset($data['chuanghuiBankCode']) ? trim($data['chuanghuiBankCode']) : '';
  27. }
  28. if ($data['payType'] == 5) {
  29. $data['bankCode'] = isset($data['shanfutongBankCode']) ? trim($data['shanfutongBankCode']) : '';
  30. }
  31. if ($data['payType'] == 6) {
  32. $data['bankCode'] = isset($data['kuaifuBankCode']) ? trim($data['kuaifuBankCode']) : '';
  33. }
  34. if ($data['payType'] == 7) {
  35. $data['bankCode'] = isset($data['kuaifu2BankCode']) ? trim($data['kuaifu2BankCode']) : '';
  36. }
  37. $model->setAttributes($data);
  38. if ($model->outPay()) {
  39. $result = $model->getOutPayResult();
  40. if ($result['type'] == 'html') {
  41. if($data['payType'] == 1){
  42. if($result['html']['code']==200){
  43. $url = $result['html']['data']['url'];
  44. header("location:$url");
  45. exit;
  46. }else{
  47. echo $result['html']['message'];
  48. exit;
  49. }
  50. }
  51. return $result['html'];
  52. }else {
  53. throw new BadRequestHttpException('支付异常');
  54. }
  55. } else {
  56. throw new BadRequestHttpException(json_encode($model->getErrors(), 320));
  57. }
  58. }
  59. throw new BadRequestHttpException('Bad Request');
  60. }
  61. public function actionSucceed()
  62. {
  63. return $this->render('succeed');
  64. }
  65. public function actionFailed()
  66. {
  67. return $this->render('failed');
  68. }
  69. public function sandPayHtmlHandler($result)
  70. {
  71. $jqueryJs = STATIC_URL.'/ui/js/sand/jquery-1.7.2.min.js';
  72. $paymentJs = STATIC_URL.'/ui/js/sand/paymentjs.js';
  73. $html = <<<eot
  74. <html>
  75. <head>
  76. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  77. <meta name="renderer" content="webkit" />
  78. <script type="text/javascript" src="{$jqueryJs}"></script>
  79. <script type="text/javascript" src="{$paymentJs}"></script>
  80. <script>
  81. function wap_pay() {
  82. var responseText = $("#credential").text();
  83. paymentjs.createPayment(responseText, function(result, err) {
  84. });
  85. }
  86. </script>
  87. </head>
  88. <body>
  89. <div style="display: none" >
  90. <p id="credential">{$result}</p>
  91. </div>
  92. <script>
  93. window.onload=function(){
  94. wap_pay();
  95. //window.location.href = "http://www.jb51.net";
  96. };
  97. </script>
  98. </body>
  99. </html>
  100. eot;
  101. return $html;
  102. }
  103. }