PayController.php 5.0 KB

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