PayController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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['renrenBankCode']) ? trim($data['renrenBankCode']) : '';
  21. }
  22. if ($data['payType'] == 3) {
  23. $data['bankCode'] = isset($data['sandBankCode']) ? trim($data['sandBankCode']) : '';
  24. }
  25. if ($data['payType'] == 8) {
  26. $data['bankCode'] = isset($data['kexingBankCode']) ? trim($data['kexingBankCode']) : '';
  27. }
  28. if ($data['payType'] == 10) {
  29. $data['bankCode'] = isset($data['otczhifuBankCode']) ? trim($data['otczhifuBankCode']) : '';
  30. }
  31. if ($data['payType'] == 11) {
  32. $data['amount'] = 0.00;
  33. }
  34. if ($data['payType'] == 12) {
  35. $data['amount'] = 0.00;
  36. }
  37. if ($data['payType'] == 13) {
  38. $data['amount'] = 0.00;
  39. }
  40. if ($data['payType'] == 14) {
  41. $data['amount'] = 0.00;
  42. }
  43. if ($data['payType'] == 16) {
  44. $data['bankCode'] = isset($data['duisiBankCode']) ? trim($data['duisiBankCode']) : '';
  45. $amout_back = rand(1,70);
  46. $data['amount'] = sprintf("%.2f",$data['amount']) + $amout_back/100;
  47. }
  48. if ($data['payType'] == 17) {
  49. $data['bankCode'] = isset($data['duigongBankCode']) ? trim($data['duigongBankCode']) : '';
  50. $amout_back = rand(1,70);
  51. $data['amount'] = sprintf("%.2f",$data['amount']) + $amout_back/100;
  52. }
  53. //echo "<pre>";
  54. //var_dump($data);die;
  55. $model->setAttributes($data);
  56. if ($model->outPay()) {
  57. $result = $model->getOutPayResult();
  58. if ($result['type'] == 'html') {
  59. if ($data['payType'] == 3) {
  60. return $this->sandPayHtmlHandler($result['html']);
  61. } elseif($data['payType'] == 7) {
  62. for ($i = 0; $i <= 31; ++$i) {
  63. $result['html'] = str_replace(chr($i), "", $result['html']);
  64. }
  65. $result['html'] = str_replace(chr(127), "", $result['html']);
  66. if (0 === strpos(bin2hex($result['html']), 'efbbbf')) {
  67. $result['html'] = substr($result['html'], 3);
  68. }
  69. $tmp = json_decode($result['html'], true);
  70. $arr = parse_url($tmp['qr_src']);
  71. $queryParts = explode('&', $arr['query']);
  72. $params = array();
  73. foreach ($queryParts as $param)
  74. {
  75. $item = explode('=', $param);
  76. $params[$item[0]] = $item[1];
  77. }
  78. $orderAmount = $params['amount'];
  79. //return $this->redirect($tmp['qr_src']);
  80. $qr_img = "https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl=bitcoin:{$tmp['payee_address']}?amount={$orderAmount}";
  81. $data['qr_img'] = $qr_img;
  82. $data['amount'] = $orderAmount;
  83. $data['payee_address'] = $tmp['payee_address'];
  84. return $this->render('ctypepay',['data' => $data, ]);
  85. }
  86. if($data['payType'] == 10){
  87. if($result['html']['code']==200){
  88. $url = $result['html']['data'];
  89. header("location:$url");
  90. exit;
  91. }else{
  92. echo $result['html']['msg'];
  93. exit;
  94. }
  95. }
  96. return $result['html'];
  97. } else {
  98. throw new BadRequestHttpException('支付异常');
  99. }
  100. } else {
  101. throw new BadRequestHttpException(json_encode($model->getErrors(), 320));
  102. }
  103. }
  104. throw new BadRequestHttpException('Bad Request');
  105. }
  106. public function actionSucceed()
  107. {
  108. return $this->render('succeed');
  109. }
  110. public function actionFailed()
  111. {
  112. return $this->render('failed');
  113. }
  114. public function sandPayHtmlHandler($result)
  115. {
  116. $jqueryJs = STATIC_URL.'/ui/js/sand/jquery-1.7.2.min.js';
  117. $paymentJs = STATIC_URL.'/ui/js/sand/paymentjs.js';
  118. $html = <<<eot
  119. <html>
  120. <head>
  121. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  122. <meta name="renderer" content="webkit" />
  123. <script type="text/javascript" src="{$jqueryJs}"></script>
  124. <script type="text/javascript" src="{$paymentJs}"></script>
  125. <script>
  126. function wap_pay() {
  127. var responseText = $("#credential").text();
  128. paymentjs.createPayment(responseText, function(result, err) {
  129. });
  130. }
  131. </script>
  132. </head>
  133. <body>
  134. <div style="display: none" >
  135. <p id="credential">{$result}</p>
  136. </div>
  137. <script>
  138. window.onload=function(){
  139. wap_pay();
  140. //window.location.href = "http://www.jb51.net";
  141. };
  142. </script>
  143. </body>
  144. </html>
  145. eot;
  146. return $html;
  147. }
  148. }