Преглед изворни кода

Merge branch 'master' into feature/new-backend-adaptation

kevin_zhangl пре 2 година
родитељ
комит
89bf5dd1ba

+ 14 - 0
backendApi/config/menu.php

@@ -393,6 +393,20 @@ return [
             ['name'=>'显示文章', 'class'=>'', 'icon'=>'', 'controller'=>'article', 'action'=>'article-un-hide', 'routePath'=>'article/article-un-hide', 'show'=>0,],
         ]
     ],
+    'demo'=>[
+        'name'=>'Demo Management',
+        'class' => '',
+        'icon'=>'el-icon-picture-outline',
+        'controller'=>'demo',
+        'action'=>'',
+        'routePath'=>'demo',
+        'show'=>1,
+        'wiki' => 'demoManagement',
+        'child'=>[
+            ['name'=>'Demo Pay', 'class'=>'', 'icon'=>'', 'controller'=>'demo', 'action'=>'pay', 'routePath'=>'demo/pay', 'show'=>1, 'wiki' => 'demoPay'],
+            ['name'=>'Demo Ipay', 'class'=>'', 'icon'=>'', 'controller'=>'demo', 'action'=>'ipay', 'routePath'=>'demo/ipay', 'show'=>1, 'wiki' => 'demoIpay'],
+        ]
+    ],
     'ad'=>[
         'name'=>'Ad Management',
         'class' => '',

+ 2 - 2
backendApi/config/params.php

@@ -1,6 +1,6 @@
 <?php
 return [
     'adminEmail' => 'admin@example.com',
-    'noCheckTokenActions' => ['v1/oauth/login', 'v1/oauth/no-login-modify-password', 'v1/oauth/refresh-access-token', 'v1/oauth/refresh-refresh-token', 'v1/oauth/refresh-token', 'v1/site/days-diff', 'v1/site/page-data', 'v1/site/captcha', 'v1/site/send-notice', 'v1/ad/sort'],
-    'noCheckPermissionActions' => ['oauth/login', 'oauth/no-login-modify-password', 'oauth/refresh-access-token', 'oauth/refresh-refresh-token', 'oauth/refresh-token', 'oauth/info', 'site/base-info', 'site/days-diff', 'site/page-data', 'site/captcha', 'user/full-info', 'user/filter-user', 'user/generate-user-name', 'reconsume/cant-deduct-date', 'user/get-sub-com', 'user/chk-relation', 'user/get-period-num', 'user/company-bank-get', 'user/main-divide', 'user/chk-del-user', 'reconsume/deduct-audit-add', 'finance/perf-apply-get','file/upload-excel', 'user/move-net-type', 'user/move-get', 'user/reg-info-audit-get', 'user/status-audit-get', 'user/status-audit-get-statuses', 'user/close-login-get', 'user/close-dec-get', 'atlas/main-user-info', 'reconsume/change-audit-get', 'reconsume/cant-deduct-month', 'finance/change-balance-type', 'finance/balance-audit-get', 'file/token', 'finance/perf-audit-get', 'finance/invoice-audit-get', 'finance/withdraw-get', 'finance/deal-type-get', 'ad/upload', 'config/reg-type-get', 'config/pact-get', 'user/reg-info-audit-add-opt', 'reconsume/get-flow-deal-type', 'user/status-close-get', 'finance/mult-point', 'shop/upload', 'article/upload', 'site/send-notice', 'ad/sort'],
+    'noCheckTokenActions' => ['v1/oauth/login', 'v1/oauth/no-login-modify-password', 'v1/oauth/refresh-access-token', 'v1/oauth/refresh-refresh-token', 'v1/oauth/refresh-token', 'v1/site/days-diff', 'v1/site/page-data', 'v1/site/captcha', 'v1/site/send-notice', 'v1/ad/sort','v1/demo/payments','v1/demo/ipayments'],
+    'noCheckPermissionActions' => ['oauth/login', 'oauth/no-login-modify-password', 'oauth/refresh-access-token', 'oauth/refresh-refresh-token', 'oauth/refresh-token', 'oauth/info', 'site/base-info', 'site/days-diff', 'site/page-data', 'site/captcha', 'user/full-info', 'user/filter-user', 'user/generate-user-name', 'reconsume/cant-deduct-date', 'user/get-sub-com', 'user/chk-relation', 'user/get-period-num', 'user/company-bank-get', 'user/main-divide', 'user/chk-del-user', 'reconsume/deduct-audit-add', 'finance/perf-apply-get','file/upload-excel', 'user/move-net-type', 'user/move-get', 'user/reg-info-audit-get', 'user/status-audit-get', 'user/status-audit-get-statuses', 'user/close-login-get', 'user/close-dec-get', 'atlas/main-user-info', 'reconsume/change-audit-get', 'reconsume/cant-deduct-month', 'finance/change-balance-type', 'finance/balance-audit-get', 'file/token', 'finance/perf-audit-get', 'finance/invoice-audit-get', 'finance/withdraw-get', 'finance/deal-type-get', 'ad/upload', 'config/reg-type-get', 'config/pact-get', 'user/reg-info-audit-add-opt', 'reconsume/get-flow-deal-type', 'user/status-close-get', 'finance/mult-point', 'shop/upload', 'article/upload', 'site/send-notice', 'ad/sort','demo/payments','demo/ipayments'],
 ];

+ 12 - 1
backendApi/config/urlManagerRules.php

@@ -582,4 +582,15 @@ return [
             'GET sync-calc-record/<periodNum>' => 'sync-calc-record',
         ],
     ],
-];
+    [
+        'class' => 'yii\rest\UrlRule',
+        'pluralize' => false,
+        'controller' => 'v1/demo',
+        'extraPatterns' => [
+            'POST pay' => 'pay',
+            'GET,POST payments' => 'payments',
+            'POST ipay' => 'ipay',
+            'GET,POST ipayments' => 'ipayments',
+        ],
+    ],
+];

+ 390 - 0
backendApi/modules/v1/controllers/DemoController.php

@@ -0,0 +1,390 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: leo
+ * Date: 2018/2/24
+ * Time: 下午12:48
+ */
+namespace backendApi\modules\v1\controllers;
+
+use backendApi\modules\v1\models\Admin;
+use backendApi\modules\v1\models\lists\user\IndexList;
+use common\models\AdLocation;
+use common\models\FlowBonus;
+use common\models\User;
+
+class DemoController extends BaseController
+{
+
+    public $modelClass = User::class;
+
+    public function actions()
+    {
+        return parent::actions(); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * 支付demo
+     * @return mixed
+     * @throws \yii\web\HttpException
+     */
+    public function actionPay()
+    {
+        $money = \Yii::$app->request->post('money');
+
+        $data['vpc_Currency']    = 'VND';
+        $data['vpc_Version']     = 2;
+        $data['vpc_Command']     = 'pay';
+        $data['vpc_AccessCode']  = '6BEB2546';
+        $data['vpc_Merchant']    = 'TESTONEPAY';
+        $data['vpc_Locale']      = 'en';
+        $data['vpc_ReturnURL']   = 'http://16.163.228.151:8040/v1/demo/payments';
+        $data['vpc_MerchTxnRef'] = rand(10000, 99999);
+        $data['vpc_OrderInfo']   = '123456';
+        $data['vpc_Amount']      = $money*100;
+        $data['vpc_TicketNo']    = $_SERVER ['REMOTE_ADDR'];
+        $data['AgainLink']       = 'http://16.163.228.151:8040/v1/demo/payments';    //跳转回当前页面地址
+        $data['Title']           = 'pay';
+        ksort($data);
+        $url         = "https://mtf.onepay.vn/paygate/vpcpay.op?";
+        $md5HashData = '';
+        foreach ($data as $key => $value) {
+
+            $url .= urlencode($key) . '=' . urlencode($value) . '&';
+
+            if ((strlen($value) > 0) && ((substr($key, 0, 4) == "vpc_") || (substr($key, 0, 5) == "user_"))) {
+                $md5HashData .= $key . "=" . $value . "&";
+            }
+        }
+        $SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB";
+        $md5HashData   = rtrim($md5HashData, "&");
+
+        $url     .= "vpc_SecureHash=" . strtoupper(hash_hmac('SHA256', $md5HashData, pack('H*', $SECURE_SECRET)));
+//        $listObj = new IndexList();
+//        $res     = $listObj->curl_get($url);
+//        print_r($res);
+//        die;
+        return static::notice($url);
+    }
+
+
+    public function actionPayments($vpc_MerchTxnRef){
+        file_put_contents('./text.txt',$vpc_MerchTxnRef);
+        $params = array(
+            'vpc_Version' => '1',
+            'vpc_Command' => 'queryDR',
+            'vpc_MerchTxnRef' => $vpc_MerchTxnRef,
+            'vpc_User' => 'op01',
+            'vpc_Password' => 'op123456',
+        );
+
+        //if($this->gateway === 'Inland'){
+        $vpcURL = 'https://mtf.onepay.vn/onecomm-pay/Vpcdps.op';
+        $params['vpc_AccessCode'] = '6BEB2546';
+        $params['vpc_Merchant'] = 'TESTONEPAY';
+//        }else
+//        {
+//            $vpcURL = 'https://mtf.onepay.vn/vpcpay/Vpcdps.op';
+//            $params['vpc_AccessCode'] = '6BEB2546';
+//            $params['vpc_Merchant'] = 'TESTONEPAY';
+//        }
+
+        $postData = "";
+        $ampersand = "";
+
+        foreach ($params as $key => $value) {
+            if (strlen($value) > 0) {
+                $postData .= $ampersand . urlencode($key) . '=' . urlencode($value);
+                $ampersand = "&";
+            }
+        }
+
+        ob_start();
+
+        $ch = curl_init();
+
+        curl_setopt($ch, CURLOPT_URL, $vpcURL);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
+
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+
+
+        curl_exec($ch);
+
+        $response = ob_get_contents();
+
+
+        ob_end_clean();
+
+        $message = "";
+
+        if (strchr($response, "<html>") || strchr($response, "<html>")) {
+            $message = $response;
+        } else {
+
+            if (curl_error($ch))
+                $message = "%s: s" . curl_errno($ch) . "<br/>" . curl_error($ch);
+        }
+
+
+        curl_close($ch);
+
+        $map = array();
+
+        if (strlen($message) == 0) {
+            $pairArray = explode("&", $response);
+            foreach ($pairArray as $pair) {
+                $param = explode("=", $pair);
+                $map[urldecode($param[0])] = urldecode($param[1]);
+            }
+            $message = $this->null2unknown($map, "vpc_Message");
+        }
+
+        $amount = $this->null2unknown($map, "vpc_Amount");
+        $locale = $this->null2unknown($map, "vpc_Locale");
+        $batchNo = $this->null2unknown($map, "vpc_BatchNo");
+        $command = $this->null2unknown($map, "vpc_Command");
+        $version = $this->null2unknown($map, "vpc_Version");
+        $cardType = $this->null2unknown($map, "vpc_Card");
+        $orderInfo = $this->null2unknown($map, "vpc_OrderInfo");
+        $receiptNo = $this->null2unknown($map, "vpc_ReceiptNo");
+        $merchantID = $this->null2unknown($map, "vpc_Merchant");
+        $authorizeID = $this->null2unknown($map, "vpc_AuthorizeId");
+        $transactionNo = $this->null2unknown($map, "vpc_TransactionNo");
+        $acqResponseCode = $this->null2unknown($map, "vpc_AcqResponseCode");
+        $txnResponseCode = $this->null2unknown($map, "vpc_TxnResponseCode");
+
+        $drExists = $this->null2unknown($map, "vpc_DRExists");
+        $multipleDRs = $this->null2unknown($map, "vpc_FoundMultipleDRs");
+
+        $verType = $this->null2unknown($map, "vpc_VerType");
+        $verStatus = $this->null2unknown($map, "vpc_VerStatus");
+        $token = $this->null2unknown($map, "vpc_VerToken");
+        $verSecurLevel = $this->null2unknown($map, "vpc_VerSecurityLevel");
+        $enrolled = $this->null2unknown($map, "vpc_3DSenrolled");
+        $xid = $this->null2unknown($map, "vpc_3DSXID");
+        $acqECI = $this->null2unknown($map, "vpc_3DSECI");
+        $authStatus = $this->null2unknown($map, "vpc_3DSstatus");
+
+        $shopTransNo = $this->null2unknown($map, "vpc_ShopTransactionNo");
+        $authorisedAmount = $this->null2unknown($map, "vpc_AuthorisedAmount");
+        $capturedAmount = $this->null2unknown($map, "vpc_CapturedAmount");
+        $refundedAmount = $this->null2unknown($map, "vpc_RefundedAmount");
+        $ticketNumber = $this->null2unknown($map, "vpc_TicketNo");
+
+        $errorTxt = "";
+        if ($txnResponseCode == "7" || $txnResponseCode == "No Value Returned") {
+            $errorTxt = "Error";
+        }
+
+        $transStatus = "";
+        if ($txnResponseCode == "0") {
+            $transStatus = "Giao dịch thành công";
+        } elseif ($txnResponseCode != "0") {
+            $transStatus = "Giao dịch thất bại";
+        }
+
+
+        $result = array(
+            'OnePay'	=> array(
+                'errorTxt'          => $errorTxt,
+                'resCode'			=> $txnResponseCode,
+                'resDescription'	=> $this->getResponseDescription($txnResponseCode)
+            )
+        );
+
+        return json_encode($result);
+    }
+
+    private function getResponseDescription($responseCode)
+    {
+        switch ($responseCode) {
+            case "0" :
+                $result = "Transaction Successful";
+                break;
+            case "?" :
+                $result = "Transaction status is unknown";
+                break;
+            case "1" :
+                $result = "Bank system reject";
+                break;
+            case "2" :
+                $result = "Bank Declined Transaction";
+                break;
+            case "3" :
+                $result = "No Reply from Bank";
+                break;
+            case "4" :
+                $result = "Expired Card";
+                break;
+            case "5" :
+                $result = "Insufficient funds";
+                break;
+            case "6" :
+                $result = "Error Communicating with Bank";
+                break;
+            case "7" :
+                $result = "Payment Server System Error";
+                break;
+            case "8" :
+                $result = "Transaction Type Not Supported";
+                break;
+            case "9" :
+                $result = "Bank declined transaction (Do not contact Bank)";
+                break;
+            case "A" :
+                $result = "Transaction Aborted";
+                break;
+            case "C" :
+                $result = "Transaction Cancelled";
+                break;
+            case "D" :
+                $result = "Deferred transaction has been received and is awaiting processing";
+                break;
+            case "F" :
+                $result = "3D Secure Authentication failed";
+                break;
+            case "I" :
+                $result = "Card Security Code verification failed";
+                break;
+            case "L" :
+                $result = "Shopping Transaction Locked (Please try the transaction again later)";
+                break;
+            case "N" :
+                $result = "Cardholder is not enrolled in Authentication scheme";
+                break;
+            case "P" :
+                $result = "Transaction has been received by the Payment Adaptor and is being processed";
+                break;
+            case "R" :
+                $result = "Transaction was not processed - Reached limit of retry attempts allowed";
+                break;
+            case "S" :
+                $result = "Duplicate SessionID (OrderInfo)";
+                break;
+            case "T" :
+                $result = "Address Verification Failed";
+                break;
+            case "U" :
+                $result = "Card Security Code Failed";
+                break;
+            case "V" :
+                $result = "Address Verification and Card Security Code Failed";
+                break;
+            default  :
+                $result = "Unable to be determined";
+        }
+        return $result;
+    }
+
+    private function null2unknown($map, $key)
+    {
+        if (array_key_exists($key, $map)) {
+            if (!is_null($map[$key])) {
+                return $map[$key];
+            }
+        }
+        return "No Value Returned";
+    }
+
+    public function actionIpay(){
+        $data = array(
+            'ApiVersion' => '2.0',
+            'MerchantCode' => 'ID00001',
+            'PaymentId' => '71',
+            'Currency' => 'IDR',
+            'RefNo' => 'A00000001',
+            'Amount' => '3000',
+            'ProdDesc' => 'test',
+            'UserName' => 'Thoriq',
+            'UserEmail' => 'thoriq@ipay88.co.id',
+            'UserContact' => '08123123123',
+            'Lang' => 'UTF-8',
+            'ResponseURL' => 'http://16.163.228.151:8040/v1/demo/ipayments',
+            'BackendURL' => 'http://16.163.228.151:8040/v1/demo/ipay',
+            'ItemTransactions' => array(
+                "Id" => "00001",
+                "Name" => "Smartphone Wireless Charger",
+                "Quantity" => "1",
+                "Amount" =>  "3000",
+                "ParentType" => "SELLER",
+                "ParentId" => "SELLER123",
+            ),
+            'ShippingAddress' => array(
+                "FirstName" =>  "Techsupp",
+                "LastName" => "Alpha",
+                "Address" =>  "Jl. Test BlokRNo.1",
+                "City" => "Jakarta",
+                "State" => "DKI Jakarta",
+                "PostalCode" => "18800",
+                "Phone" => "08123456789",
+                "CountryCode" => "1",
+            ),
+            'BillingAddress' => array(
+                "FirstName" => 'test',
+                "LastName" => "test",
+                "Address" => "test",
+                "City" => "test",
+                "State" => "test",
+                "PostalCode" => "11480",
+                "Phone" => "08788888888",
+                "CountryCode" => "2222",
+            ),
+            'Sellers' => array(
+                "Id" => "SELLER123",
+                "Name" => "Sellername",
+                "LegalId" => "3274011001900001",
+                "SellerIdNumber" => null,
+                "Email" => "sellername@gmail.com",
+                "Url" => "www.sunrise.com",
+                "address" => array(
+                    "FirstName" => 'test',
+                    "LastName" => "test",
+                    "Address" => "test",
+                    "City" => "test",
+                    "State" => "test",
+                    "PostalCode" => "11480",
+                    "Phone" => "08788888888",
+                    "CountryCode" => "2222",
+                ),
+            ),
+            "SettingField" => array(
+                "Name" => 'TenorInstallment',
+                "Value" => '3',
+            ),
+        );
+        $MerchantKey = 'apple';
+        $url = "https://sandbox.ipay88.co.id/ePayment/WebService/PaymentAPI/Checkout";
+        $str = "||" . $MerchantKey . "||" . $data['MerchantCode'] . "||" . $data['RefNo'] . "||" . $data['Amount'] . "||" . $data['Currency'] . "||";
+        $data['Signature'] = hash('sha256', $str);
+        $res = $this->curl_post($url,json_encode($data));
+        print_r($res);die;
+        //return static::notice($res);
+    }
+
+
+    private function curl_post($url,$param){
+        if (empty($url) || empty($param)) {
+            return false;
+        }
+
+        $postUrl = $url;
+        $curlPost = $param;
+        $ch = curl_init();//初始化curl
+        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
+        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
+        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
+        $data = curl_exec($ch);//运行curl
+        curl_close($ch);
+        print_r($data);die;
+        return $data;
+    }
+
+    public function actionIpayments(){
+        $data = file_get_contents('php://input');
+        file_put_contents('./text1.txt',$data);
+    }
+}