| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- namespace backend\modules\user\controllers;
- use backend\models\forms\PayForm;
- use Yii;
- use yii\web\BadRequestHttpException;
- class PayController extends BaseController
- {
- /**
- * @return \yii\web\Response
- * @throws \Exception
- */
- public function actionOutpay()
- {
- $model = new PayForm();
- if (Yii::$app->getRequest()->getIsPost()) {
- $data = Yii::$app->getRequest()->post();
- $payMethod = isset($data['payMethod']) ? trim($data['payMethod']) : '';
- $data['payType'] = $model->getPayTypeByMethod($payMethod);
- if ($data['payType'] == 1) {
- $data['bankCode'] = isset($data['renrenBankCode']) ? trim($data['renrenBankCode']) : '';
- }
- if ($data['payType'] == 3) {
- $data['bankCode'] = isset($data['sandBankCode']) ? trim($data['sandBankCode']) : '';
- }
- if ($data['payType'] == 8) {
- $data['bankCode'] = isset($data['kexingBankCode']) ? trim($data['kexingBankCode']) : '';
- }
- if ($data['payType'] == 10) {
- $data['bankCode'] = isset($data['otczhifuBankCode']) ? trim($data['otczhifuBankCode']) : '';
- }
- if ($data['payType'] == 11) {
- $data['amount'] = 0.00;
- }
- if ($data['payType'] == 12) {
- $data['amount'] = 0.00;
- }
- if ($data['payType'] == 13) {
- $data['amount'] = 0.00;
- }
- if ($data['payType'] == 14) {
- $data['amount'] = 0.00;
- }
- if ($data['payType'] == 16) {
- $data['bankCode'] = isset($data['duisiBankCode']) ? trim($data['duisiBankCode']) : '';
- $amout_back = rand(1,70);
- $data['amount'] = sprintf("%.2f",$data['amount']) + $amout_back/100;
- }
- if ($data['payType'] == 17) {
- $data['bankCode'] = isset($data['duigongBankCode']) ? trim($data['duigongBankCode']) : '';
- $amout_back = rand(1,70);
- $data['amount'] = sprintf("%.2f",$data['amount']) + $amout_back/100;
- }
- if ($data['payType'] == 18) {
- $data['bankCode'] = isset($data['globalpayBankCode']) ? trim($data['globalpayBankCode']) : '';
- }
- if ($data['payType'] == 19) {
- $data['bankCode'] = isset($data['payplatBankCode']) ? trim($data['payplatBankCode']) : '';
- }
- $model->setAttributes($data);
- if ($model->outPay()) {
- $result = $model->getOutPayResult();
- if ($result['type'] == 'html') {
- if ($data['payType'] == 3) {
- return $this->sandPayHtmlHandler($result['html']);
- } elseif($data['payType'] == 7) {
- for ($i = 0; $i <= 31; ++$i) {
- $result['html'] = str_replace(chr($i), "", $result['html']);
- }
- $result['html'] = str_replace(chr(127), "", $result['html']);
- if (0 === strpos(bin2hex($result['html']), 'efbbbf')) {
- $result['html'] = substr($result['html'], 3);
- }
- $tmp = json_decode($result['html'], true);
- $arr = parse_url($tmp['qr_src']);
- $queryParts = explode('&', $arr['query']);
- $params = array();
- foreach ($queryParts as $param)
- {
- $item = explode('=', $param);
- $params[$item[0]] = $item[1];
- }
-
- $orderAmount = $params['amount'];
- //return $this->redirect($tmp['qr_src']);
- $qr_img = "https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl=bitcoin:{$tmp['payee_address']}?amount={$orderAmount}";
- $data['qr_img'] = $qr_img;
- $data['amount'] = $orderAmount;
- $data['payee_address'] = $tmp['payee_address'];
- return $this->render('ctypepay',['data' => $data, ]);
- }
- if($data['payType'] == 10){
- if($result['html']['code']==200){
- $url = $result['html']['data'];
- header("location:$url");
- exit;
- }else{
- echo $result['html']['msg'];
- exit;
- }
- }
- if($data['payType'] == 18){
- if($result['html']['code']==200){
- $url = $result['html']['pay_url'];
- header("location:$url");
- exit;
- }else{
- echo $result['html']['error'];
- exit;
- }
- }
- return $result['html'];
- } else {
- throw new BadRequestHttpException('支付异常');
- }
- } else {
- throw new BadRequestHttpException(json_encode($model->getErrors(), 320));
- }
- }
- throw new BadRequestHttpException('Bad Request');
- }
- public function actionSucceed()
- {
- return $this->render('succeed');
- }
- public function actionFailed()
- {
- return $this->render('failed');
- }
- public function sandPayHtmlHandler($result)
- {
- $jqueryJs = STATIC_URL.'/ui/js/sand/jquery-1.7.2.min.js';
- $paymentJs = STATIC_URL.'/ui/js/sand/paymentjs.js';
- $html = <<<eot
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="renderer" content="webkit" />
- <script type="text/javascript" src="{$jqueryJs}"></script>
- <script type="text/javascript" src="{$paymentJs}"></script>
- <script>
- function wap_pay() {
- var responseText = $("#credential").text();
- paymentjs.createPayment(responseText, function(result, err) {
- });
- }
- </script>
- </head>
- <body>
- <div style="display: none" >
- <p id="credential">{$result}</p>
- </div>
- <script>
- window.onload=function(){
- wap_pay();
- //window.location.href = "http://www.jb51.net";
- };
- </script>
- </body>
- </html>
- eot;
- return $html;
- }
- }
|