| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?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['huanqiuBankCode']) ? trim($data['huanqiuBankCode']) : '';
- }
- if ($data['payType'] == 2) {
- $data['bankCode'] = isset($data['payflashBankCode']) ? trim($data['payflashBankCode']) : ''; //支付方式
- }
- if ($data['payType'] == 4) {
- $data['bankCode'] = isset($data['chuanghuiBankCode']) ? trim($data['chuanghuiBankCode']) : '';
- }
- if ($data['payType'] == 5) {
- $data['bankCode'] = isset($data['shanfutongBankCode']) ? trim($data['shanfutongBankCode']) : '';
- }
- if ($data['payType'] == 6) {
- $data['bankCode'] = isset($data['kuaifuBankCode']) ? trim($data['kuaifuBankCode']) : '';
- }
- if ($data['payType'] == 7) {
- $data['bankCode'] = isset($data['kuaifu2BankCode']) ? trim($data['kuaifu2BankCode']) : '';
- }
-
- $model->setAttributes($data);
- if ($model->outPay()) {
- $result = $model->getOutPayResult();
- if ($result['type'] == 'html') {
-
- if($data['payType'] == 1){
- if($result['html']['code']==200){
- $url = $result['html']['data']['url'];
- header("location:$url");
- exit;
- }else{
- echo $result['html']['message'];
- 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;
- }
- }
|