shish 3 lat temu
rodzic
commit
3bae36a316

+ 208 - 179
app-ghs/controllers/TestController.php

@@ -13,8 +13,10 @@ use bizGhs\express\services\MiniExpressService;
 use bizGhs\product\classes\ProductClass;
 use common\components\baiduAip;
 use common\components\barcodeUtil;
-use common\components\dada\dada;
+
+use common\components\lakala\Lakala;
 use common\components\miniUtil;
+use common\components\orderSn;
 use common\components\oss;
 use common\components\wxUtil;
 use Yii;
@@ -23,24 +25,50 @@ use common\components\util;
 class TestController extends BaseController
 {
 
-	public $guestAccess = ['inform', 'notice','order-query','add-order','index'];
+    public $guestAccess = ['inform', 'notice', 'order-query', 'add-order', 'index'];
+
+
+    public function actionRun()
+    {
+        $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/cs_private_key.pem';
+        $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/cs_cert.cer';
+        $params = [
+            'appid' => 'OP00000003',
+            'mchSerialNo' => '00dfba8194c41b84cf',
+            'mercId' => '8221210594300JY',
+            'termNo' => 'A0073841',
+            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+            'lklCertificatePath' => $lklCertificatePath,
+        ];
+        $lakala = new Lakala($params);
+        $outTradeNo = orderSn::getPurchaseSn();
+        $price = 0.1;
+        $response = $lakala->aliPay($outTradeNo, $price);
+        if ($response && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
+            echo '下单成功';
+            print_r($response);
+        } else {
+            echo '下单失败';
+            print_r($response);
+        }
+    }
 
 
-	public function actionIndex()
+    public function actionIndex()
     {
         //header('Content-type:image/png');
         $productId = 1;
         $barcode = barcodeUtil::barcodeGeneratorPNG($productId);
-        oss::uploadContent("ghs/barcode/".$productId.'.png',$barcode);
+        oss::uploadContent("ghs/barcode/" . $productId . '.png', $barcode);
         $barcode = base64_encode($barcode);
-        echo  ' <img src="data:image/png;base64,'. $barcode .'"/>';
+        echo ' <img src="data:image/png;base64,' . $barcode . '"/>';
 //        $merchantExtend = WxOpenClass::getGhsWxInfo();
 //       // $res = baiduAip::transfer("你好");
 //        dd($merchantExtend);
     }
 
-	//dada 城市code
-	public function actionDadaCityCode()
+    //dada 城市code
+    public function actionDadaCityCode()
     {
         $res = dada::getCityCode(0);
         util::success($res);
@@ -78,11 +106,12 @@ class TestController extends BaseController
         $res = DadaExpressServices::statusOrder($orderSn);
         util::success($res);
     }
+
     //达达取消下单
     public function actionDadaCancelOrder()
     {
         $orderSn = 'XSD_CS26316851';
-        $res = DadaExpressServices::cancelOrder($orderSn,1);
+        $res = DadaExpressServices::cancelOrder($orderSn, 1);
         util::success($res);
     }
 
@@ -124,70 +153,71 @@ class TestController extends BaseController
 
 
     //下单 (沙箱)
+
     /**
      * Array
-    (
-    [resultcode] => 0
-    [resultmsg] => ok
-    [fee] => 10
-    [waybill_id] => test_shop_id1612365974_waybillid
-    [order_status] => 101
-    [dispatch_duration] => 300
-    )
+     * (
+     * [resultcode] => 0
+     * [resultmsg] => ok
+     * [fee] => 10
+     * [waybill_id] => test_shop_id1612365974_waybillid
+     * [order_status] => 101
+     * [dispatch_duration] => 300
+     * )
      */
     public function actionCreateWaybill()
     {
         $merchant = WxOpenClass::getGhsWxInfo();
         $isOpen = 2;
         $shopId = 'test_shop_id';
-        $shopOrderId = 'test_shop_id'.time();
+        $shopOrderId = 'test_shop_id' . time();
         $appSecret = 'test_app_secrect';
         $data = [
-            'shopid'=>$shopId,
-            'shop_order_id'=>$shopOrderId,
-            'shop_no'=>'1',
-            'delivery_sign'=>miniUtil::getDeliverySign($shopId,$shopOrderId,$appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
-            'delivery_id'=>"TEST",
-            'openid'=>'oGKMp45YLxewOTWEbpMFzWoVqdW0',
-            'sender'=>[
-                'name'=>'test',
-                'city'=>'厦门市',
-                'address'=>'思明区',
-                'address_detail'=>'软件园二期',
-                'phone'=>'19959271111',
-                'lng'=>118.134343,
-                'lat'=>24.483566,
-                'coordinate_type'=>0,
+            'shopid' => $shopId,
+            'shop_order_id' => $shopOrderId,
+            'shop_no' => '1',
+            'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret)
+            'delivery_id' => "TEST",
+            'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0',
+            'sender' => [
+                'name' => 'test',
+                'city' => '厦门市',
+                'address' => '思明区',
+                'address_detail' => '软件园二期',
+                'phone' => '19959271111',
+                'lng' => 118.134343,
+                'lat' => 24.483566,
+                'coordinate_type' => 0,
             ],
-            'receiver'=>[
-                'name'=>'test',
-                'city'=>'厦门市',
-                'address'=>'思明区',
-                'address_detail'=>'软件园二期',
-                'phone'=>'19959271111',
-                'lng'=>118.134343,
-                'lat'=>24.493566,
-                'coordinate_type'=>0,
+            'receiver' => [
+                'name' => 'test',
+                'city' => '厦门市',
+                'address' => '思明区',
+                'address_detail' => '软件园二期',
+                'phone' => '19959271111',
+                'lng' => 118.134343,
+                'lat' => 24.493566,
+                'coordinate_type' => 0,
             ],
-            'cargo'=>[
-                'goods_value'=>1,
-                'goods_weight'=>0.1,
-                'cargo_first_class'=>'鲜花',
-                'cargo_second_class'=>'鲜花',
+            'cargo' => [
+                'goods_value' => 1,
+                'goods_weight' => 0.1,
+                'cargo_first_class' => '鲜花',
+                'cargo_second_class' => '鲜花',
             ],
-            'order_info'=>[
-                'order_type'=>0,
+            'order_info' => [
+                'order_type' => 0,
             ],
-            'shop'=>[
-                'wxa_path'=>'/shop',
-                'img_url'=>'http://www.baidu.com/test.png',
-                'goods_name'=>'test',
-                'goods_count'=>1,
+            'shop' => [
+                'wxa_path' => '/shop',
+                'img_url' => 'http://www.baidu.com/test.png',
+                'goods_name' => 'test',
+                'goods_count' => 1,
             ],
 
         ];
 
-        $r = miniUtil::addOrder($data,$merchant, $isOpen);
+        $r = miniUtil::addOrder($data, $merchant, $isOpen);
         dd($r);
 
     }
@@ -196,34 +226,34 @@ class TestController extends BaseController
 
     /**
      * Array
-    (
-    [resultcode] => 0
-    [resultmsg] => ok
-    [order_status] => 101
-    [agent_info] => Array
-    (
-    )
-
-    [waybill_id] => test_shop_id1612365974_waybillid
-    [rider_name] =>
-    [rider_phone] =>
-    [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
-    )
+     * (
+     * [resultcode] => 0
+     * [resultmsg] => ok
+     * [order_status] => 101
+     * [agent_info] => Array
+     * (
+     * )
+     *
+     * [waybill_id] => test_shop_id1612365974_waybillid
+     * [rider_name] =>
+     * [rider_phone] =>
+     * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew
+     * )
      */
     public function actionGetOrder()
     {
         $shopId = 'test_shop_id';
-        $shopOrderId ='test_shop_id1612365974';
+        $shopOrderId = 'test_shop_id1612365974';
         $appSecret = 'test_app_secrect';
         $merchant = WxOpenClass::getGhsWxInfo();
         $isOpen = 2;
         $data = [
-            'shopid'=>$shopId,
-            'shop_order_id'=>$shopOrderId,
-            'shop_no'=>'1',
-            'delivery_sign'=>MiniExpressService::getDeliverySign($shopId,$shopOrderId,$appSecret),
+            'shopid' => $shopId,
+            'shop_order_id' => $shopOrderId,
+            'shop_no' => '1',
+            'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret),
         ];
-        $r = miniUtil::getOrder($data,$merchant, $isOpen);
+        $r = miniUtil::getOrder($data, $merchant, $isOpen);
         dd($r);
     }
 
@@ -235,24 +265,24 @@ class TestController extends BaseController
         $isOpen = 2;
         /**
          * {
-        "shopid": "test_shop_id",
-        "shop_order_id": "xxxxxxxxxxx",
-        "waybill_id": "xxxxxxxxxxxxx",
-        "action_time": 12345678,
-        "order_status": 101,
-        "action_msg": "",
-        }
+         * "shopid": "test_shop_id",
+         * "shop_order_id": "xxxxxxxxxxx",
+         * "waybill_id": "xxxxxxxxxxxxx",
+         * "action_time": 12345678,
+         * "order_status": 101,
+         * "action_msg": "",
+         * }
          */
         $shopId = 'test_shop_id';
-        $shopOrderId ='test_shop_id1612365974';
+        $shopOrderId = 'test_shop_id1612365974';
         $data = [
-            'shop_order_id'=>$shopOrderId,
-            "shopid"=>$shopId,
-            "action_time"=>time(),
-            "order_status"=>302,
-            'action_msg'=>'状态变更',
+            'shop_order_id' => $shopOrderId,
+            "shopid" => $shopId,
+            "action_time" => time(),
+            "order_status" => 302,
+            'action_msg' => '状态变更',
         ];
-        $r = miniUtil::mockUpdateOrder($data,$merchant, $isOpen);
+        $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen);
         dd($r);
     }
 
@@ -263,98 +293,97 @@ class TestController extends BaseController
     }
 
 
+    //新增订单
+    public function actionAddOrder()
+    {
+        $dada = Yii::getAlias("@vendor/dada/");
+        require_once $dada . 'api/addOrderApi.php';
+        require_once $dada . 'client/dadaRequestClient.php';
+        require_once $dada . 'client/dadaResponse.php';
+        require_once $dada . 'config/config.php';
+        require_once $dada . 'model/orderModel.php';
+
+        // isOnline 判断是否是测试环境,会有不同的域名等
+        $isOnline = false;
+        $sourceId = 1000000;
+        // 初始化一个config
+        $config = new \Config($sourceId, $isOnline);
+
+        $orderModel = new \OrderModel();
+        $orderModel->setShopNo('11047059');
+        $orderModel->setOriginId('2018091100000002');
+        $orderModel->setCityCode('021');
+        $orderModel->setCargoPrice(10);
+        $orderModel->setIsPrepay(0);
+        $orderModel->setReceiverName('测试达达');
+        $orderModel->setReceiverAddress('上海市崇明岛');
+        $orderModel->setReceiverLat(31.63);
+        $orderModel->setReceiverLng(121.41);
+        $orderModel->setReceiverPhone('18588888888');
+        $orderModel->setCallback('http://api.b.huaml.com/data/request');
+
+        // api主要有2个参数,一个是url, 一个是业务参数
+        $addOrderApi = new \AddOrderApi(json_encode($orderModel));
+
+        $dada_client = new \DadaRequestClient($config, $addOrderApi);
+        $resp = $dada_client->makeRequest();
+        echo json_encode($resp);
+    }
+
+    //订单详情查询
+    public function actionOrderQuery()
+    {
+        $dada = Yii::getAlias("@vendor/dada/");
+        require_once $dada . 'api/OrderQueryApi.php';
+        require_once $dada . 'client/dadaRequestClient.php';
+        require_once $dada . 'client/dadaResponse.php';
+        require_once $dada . 'config/config.php';
+        require_once $dada . 'model/orderModel.php';
+
+        // isOnline 判断是否是测试环境,会有不同的域名等
+        $isOnline = false;
+        $sourceId = 1000000;
+        // 初始化一个config
+        $config = new \Config($sourceId, $isOnline);
+
+        $orderModel = new \OrderModel();
+        $orderModel->setOrderId('2018091100000002');
+
+        // api主要有2个参数,一个是url, 一个是业务参数
+        $addOrderApi = new \OrderQueryApi(json_encode($orderModel));
+
+        $dada_client = new \DadaRequestClient($config, $addOrderApi);
+        $resp = $dada_client->makeRequest();
+        echo json_encode($resp);
+    }
+
+    public function actionFocus()
+    {
+        $name = '花卉宝';
+        if (getenv('YII_ENV') == 'dev') {
+            $name = '花美灵';
+        }
+        $merchant = MerchantService::getByCondition(['name' => $name]);
+        $list = wxUtil::getSubscribeUserList($merchant);
+        dd($list);
+    }
+
+    //宝贝售出提醒 ssh 2020.1.30
+    public function actionInform()
+    {
+        $merchant = MerchantService::getMerchantById(12362);
+        $order = OrderService::getById(214810);
+        InformAdminClass::sendComplete($order);
+    }
 
-	//新增订单
-	public function actionAddOrder()
-	{
-		$dada = Yii::getAlias("@vendor/dada/");
-		require_once $dada . 'api/addOrderApi.php';
-		require_once $dada . 'client/dadaRequestClient.php';
-		require_once $dada . 'client/dadaResponse.php';
-		require_once $dada . 'config/config.php';
-		require_once $dada . 'model/orderModel.php';
-
-		// isOnline 判断是否是测试环境,会有不同的域名等
-		$isOnline = false;
-		$sourceId = 1000000;
-		// 初始化一个config
-		$config = new \Config($sourceId, $isOnline);
-
-		$orderModel = new \OrderModel();
-		$orderModel->setShopNo('11047059');
-		$orderModel->setOriginId('2018091100000002');
-		$orderModel->setCityCode('021');
-		$orderModel->setCargoPrice(10);
-		$orderModel->setIsPrepay(0);
-		$orderModel->setReceiverName('测试达达');
-		$orderModel->setReceiverAddress('上海市崇明岛');
-		$orderModel->setReceiverLat(31.63);
-		$orderModel->setReceiverLng(121.41);
-		$orderModel->setReceiverPhone('18588888888');
-		$orderModel->setCallback('http://api.b.huaml.com/data/request');
-
-		// api主要有2个参数,一个是url, 一个是业务参数
-		$addOrderApi = new \AddOrderApi(json_encode($orderModel));
-
-		$dada_client = new \DadaRequestClient($config, $addOrderApi);
-		$resp = $dada_client->makeRequest();
-		echo json_encode($resp);
-	}
-
-	//订单详情查询
-	public function actionOrderQuery()
-	{
-		$dada = Yii::getAlias("@vendor/dada/");
-		require_once $dada . 'api/OrderQueryApi.php';
-		require_once $dada . 'client/dadaRequestClient.php';
-		require_once $dada . 'client/dadaResponse.php';
-		require_once $dada . 'config/config.php';
-		require_once $dada . 'model/orderModel.php';
-
-		// isOnline 判断是否是测试环境,会有不同的域名等
-		$isOnline = false;
-		$sourceId = 1000000;
-		// 初始化一个config
-		$config = new \Config($sourceId, $isOnline);
-
-		$orderModel = new \OrderModel();
-		$orderModel->setOrderId('2018091100000002');
-
-		// api主要有2个参数,一个是url, 一个是业务参数
-		$addOrderApi = new \OrderQueryApi(json_encode($orderModel));
-
-		$dada_client = new \DadaRequestClient($config, $addOrderApi);
-		$resp = $dada_client->makeRequest();
-		echo json_encode($resp);
-	}
-
-	public function actionFocus()
-	{
-		$name = '花卉宝';
-		if (getenv('YII_ENV') == 'dev') {
-			$name = '花美灵';
-		}
-		$merchant = MerchantService::getByCondition(['name' => $name]);
-		$list = wxUtil::getSubscribeUserList($merchant);
-		dd($list);
-	}
-
-	//宝贝售出提醒 ssh 2020.1.30
-	public function actionInform()
-	{
-		$merchant = MerchantService::getMerchantById(12362);
-		$order = OrderService::getById(214810);
-		InformAdminClass::sendComplete($order);
-	}
-
-	public function actionNotice()
-	{
-		$data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
-		$producer = Yii::$app->rabbitmq->getProducer('informProducer');
-		echo '<pre>';
-		print_r($data);
-		$msg = serialize($data);
-		$r = $producer->publish($msg, 'informExchange', 'informRoute');
-	}
+    public function actionNotice()
+    {
+        $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
+        $producer = Yii::$app->rabbitmq->getProducer('informProducer');
+        echo '<pre>';
+        print_r($data);
+        $msg = serialize($data);
+        $r = $producer->publish($msg, 'informExchange', 'informRoute');
+    }
 
 }

+ 196 - 0
common/components/lakala.php

@@ -0,0 +1,196 @@
+<?php
+namespace app\lakala\model;
+
+
+use app\vendor\log\Log;
+
+class Lakala {
+
+    private $appid;
+    private $mchSerialNo;
+    private $mercId;
+    private $termNo;
+    private $merchantPrivateKeyPath;
+    private $lklCertificatePath;
+    private $subject;
+    private $schema = 'LKLAPI-SHA256withRSA';
+    private $version = '1.0.0';
+    private $exterOrderSource = 'OS10000071';
+
+    public function __construct($params) {
+        $this->appid                    = $params['appid'];
+        $this->mchSerialNo              = $params['mchSerialNo'];
+        $this->mercId                   = $params['mercId'];
+        $this->termNo                   = $params['termNo'];
+        $this->merchantPrivateKeyPath   = $params['merchantPrivateKeyPath'];
+        $this->lklCertificatePath       = $params['lklCertificatePath'];
+        $this->subject                  = $params['subject'] ?? '奥式生活订单';
+    }
+
+
+	public function wechat() {
+        $reqInfo = new LabsOrderPreOrderPayReq();
+        $reqInfo->mercId = '822162070120015';
+        $reqInfo->termNo = '47827142';
+        $reqInfo->payMode = 'ALIPAY';
+        $reqInfo->openId = 'olpr-0pHIp1AjaAr29LENlHi0cJ0';
+        $reqInfo->amount = 1;
+        $reqInfo->spbillCreateIp = '127.0.0.1';
+        $reqInfo->transType = '41';
+        $reqInfo->orderId = '2020072915yhl142212';
+        $reqInfo->appId = 'wx9ef39b708f16694d';
+        $reqInfo->subject = '奥式生活订单';
+        $reqInfo->exterOrderSource = 'OS10000071';
+
+        $termExtInfo = new TermExtInfo();
+        $termExtInfo->termLoc = '';
+
+        $baseRequestVO = new BaseRequestVO();
+        $baseRequestVO->reqData = $reqInfo;
+        $baseRequestVO->termExtInfo = $termExtInfo;
+        $baseRequestVO->timestamp = random(8);
+        $baseRequestVO->ver = $this->version;
+
+        return json_encode($baseRequestVO, JSON_UNESCAPED_UNICODE);      
+    }
+
+    //支付宝
+    public function aliPay($orderId, $amount) {
+        $reqInfo = new LabsOrderPreOrderPayReq();
+        $reqInfo->mercId = $this->mercId;
+        $reqInfo->termNo = $this->termNo;
+        $reqInfo->payMode = 'ALIPAY';
+        // $reqInfo->openId = 'olpr-0pHIp1AjaAr29LENlHi0cJ0';
+        $reqInfo->amount = $amount * 100;
+        $reqInfo->spbillCreateIp = '127.0.0.1';
+        $reqInfo->transType = '41';
+        $reqInfo->orderId = $orderId;
+        // $reqInfo->appId = 'wx9ef39b708f16694d';
+        $reqInfo->subject = $this->subject;
+        $reqInfo->exterOrderSource = $this->exterOrderSource;
+
+        $termExtInfo = new TermExtInfo();
+        // $termExtInfo->termLoc = '+155621.316,-125622.12';
+
+        $baseRequestVO = new BaseRequestVO();
+        $baseRequestVO->reqData = $reqInfo;
+        $baseRequestVO->termExtInfo = $termExtInfo;
+        $baseRequestVO->timestamp = random(8);
+        $baseRequestVO->ver = $this->version;
+
+        $body = json_encode($baseRequestVO, JSON_UNESCAPED_UNICODE);
+
+        $authorization = $this->getAuthorization($body);
+
+        return $this->post(LKL_ORDERPAY_URL . '/labs_order_pre_orderpay', $body, $authorization);
+    }
+
+    //验签
+    public function signatureVerification($authorization, $body) {
+        $authorization = str_replace($this->schema . " ", "", $authorization);
+        $authorization = str_replace(",","&", $authorization);
+        $authorization = str_replace("\"","", $authorization);
+        $authorization = $this->convertUrlQuery($authorization);
+        
+        $authorization['signature'] = base64_decode($authorization['signature']);
+
+        $message = $authorization['timestamp'] . "\n" . $authorization['nonce_str'] . "\n" . $body . "\n";
+
+        $key = openssl_get_publickey(file_get_contents($this->lklCertificatePath));
+        $flag = openssl_verify($message, $authorization['signature'], $key, OPENSSL_ALGO_SHA256);
+        openssl_free_key($key);
+        if($flag) {
+            return true;
+        }
+        return false;
+    }
+
+	//签名
+	public function getAuthorization($body) {
+		$nonceStr = random(8);
+     	$timestamp = time();
+
+      	$message = $this->appid . "\n" . $this->mchSerialNo . "\n" . $timestamp . "\n" . $nonceStr . "\n" . $body . "\n";
+
+		$key = openssl_get_privatekey(file_get_contents($this->merchantPrivateKeyPath));
+
+        openssl_sign($message, $signature, $key, OPENSSL_ALGO_SHA256);
+        openssl_free_key($key);
+
+        return $this->schema . " appid=\"" . $this->appid . "\"," . "serial_no=\"" . $this->mchSerialNo . "\"," . "timestamp=\"" . $timestamp . "\"," . "nonce_str=\"" . $nonceStr . "\"," . "signature=\"" . base64_encode($signature) . "\"";
+	}
+
+    //请求
+    public function post($url, $data, $authorization) {
+
+        $headers = [
+            "Authorization: " . $authorization,
+            "Accept: application/json",
+            "Content-Type:application/json",
+        ];
+
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置HTTP头
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        $res = curl_exec($ch);
+        curl_close($ch);
+
+        return json_decode($res, 1);
+    }
+
+    //签名参数转数组
+    private function convertUrlQuery($query) { 
+        $queryParts = explode('&', $query); 
+         
+        $params = array(); 
+        foreach ($queryParts as $param) { 
+            $item = explode('=', $param); 
+            $params[$item[0]] = $item[1]; 
+        }
+        if($params['signature']) {
+            $params['signature'] = substr($query, strrpos($query, 'signature=') + 10);
+        }
+         
+        return $params; 
+    }
+
+
+}
+
+class BaseRequestVO {
+    public $reqData;
+    public $termExtInfo;
+    public $timestamp;
+    public $ver;
+}
+class LabsOrderPreOrderPayReq {
+    public $amount;
+    public $appId;
+    public $exterOrderSource;
+    public $mercId;
+    public $openId;
+    public $orderId;
+    public $payMode;
+    public $spbillCreateIp;
+    public $subject;
+    public $termNo;
+    public $transType;
+}
+
+class TermExtInfo {
+    public $termLoc;
+}
+
+
+
+
+
+
+
+
+
+

+ 9 - 0
common/components/lakala/BaseRequestVO.php

@@ -0,0 +1,9 @@
+<?php
+namespace common\components\lakala;
+
+class BaseRequestVO {
+    public $reqData;
+    public $termExtInfo;
+    public $timestamp;
+    public $ver;
+}

+ 17 - 0
common/components/lakala/LabsOrderPreOrderPayReq.php

@@ -0,0 +1,17 @@
+<?php
+namespace common\components\lakala;
+
+class LabsOrderPreOrderPayReq {
+    public $amount;
+    public $appId;
+    public $exterOrderSource;
+    public $mercId;
+    public $openId;
+    public $orderId;
+    public $payMode;
+    public $spbillCreateIp;
+    public $subject;
+    public $termNo;
+    public $transType;
+
+}

+ 175 - 0
common/components/lakala/Lakala.php

@@ -0,0 +1,175 @@
+<?php
+
+namespace common\components\lakala;
+
+class Lakala
+{
+
+    private $appid;
+    private $mchSerialNo;
+    private $mercId;
+    private $termNo;
+    private $merchantPrivateKeyPath;
+    private $lklCertificatePath;
+    private $subject;
+    private $schema = 'LKLAPI-SHA256withRSA';
+    private $version = '1.0.0';
+    private $exterOrderSource = 'OS10000071';
+    private $preUrl = '';
+
+    public function __construct($params)
+    {
+        $this->appid = $params['appid'];
+        $this->mchSerialNo = $params['mchSerialNo'];
+        $this->mercId = $params['mercId'];
+        $this->termNo = $params['termNo'];
+        $this->merchantPrivateKeyPath = $params['merchantPrivateKeyPath'];
+        $this->lklCertificatePath = $params['lklCertificatePath'];
+        $this->subject = $params['subject'] ?? '奥式生活订单';
+
+        if (getenv('YII_ENV') == 'production') {
+            $this . $preUrl = 'https://s2.lakala.com/api/v3/labs/trans/';
+        } else {
+            $this . $preUrl = 'https://test.wsmsd.cn/sit/api/v3/labs/trans/';
+        }
+
+    }
+
+
+    public function wechat()
+    {
+        $reqInfo = new LabsOrderPreOrderPayReq();
+        $reqInfo->mercId = '822162070120015';
+        $reqInfo->termNo = '47827142';
+        $reqInfo->payMode = 'ALIPAY';
+        $reqInfo->openId = 'olpr-0pHIp1AjaAr29LENlHi0cJ0';
+        $reqInfo->amount = 1;
+        $reqInfo->spbillCreateIp = '127.0.0.1';
+        $reqInfo->transType = '41';
+        $reqInfo->orderId = '2020072915yhl142212';
+        $reqInfo->appId = 'wx9ef39b708f16694d';
+        $reqInfo->subject = '奥式生活订单';
+        $reqInfo->exterOrderSource = 'OS10000071';
+
+        $termExtInfo = new TermExtInfo();
+        $termExtInfo->termLoc = '';
+
+        $baseRequestVO = new BaseRequestVO();
+        $baseRequestVO->reqData = $reqInfo;
+        $baseRequestVO->termExtInfo = $termExtInfo;
+        $baseRequestVO->timestamp = random(8);
+        $baseRequestVO->ver = $this->version;
+
+        return json_encode($baseRequestVO, JSON_UNESCAPED_UNICODE);
+    }
+
+    //支付宝
+    public function aliPay($orderId, $amount)
+    {
+        $reqInfo = new LabsOrderPreOrderPayReq();
+        $reqInfo->mercId = $this->mercId;
+        $reqInfo->termNo = $this->termNo;
+        $reqInfo->payMode = 'ALIPAY';
+        // $reqInfo->openId = 'olpr-0pHIp1AjaAr29LENlHi0cJ0';
+        $reqInfo->amount = $amount * 100;
+        $reqInfo->spbillCreateIp = '127.0.0.1';
+        $reqInfo->transType = '41';
+        $reqInfo->orderId = $orderId;
+        // $reqInfo->appId = 'wx9ef39b708f16694d';
+        $reqInfo->subject = $this->subject;
+        $reqInfo->exterOrderSource = $this->exterOrderSource;
+
+        $termExtInfo = new TermExtInfo();
+        // $termExtInfo->termLoc = '+155621.316,-125622.12';
+
+        $baseRequestVO = new BaseRequestVO();
+        $baseRequestVO->reqData = $reqInfo;
+        $baseRequestVO->termExtInfo = $termExtInfo;
+        $baseRequestVO->timestamp = random(8);
+        $baseRequestVO->ver = $this->version;
+
+        $body = json_encode($baseRequestVO, JSON_UNESCAPED_UNICODE);
+
+        $authorization = $this->getAuthorization($body);
+
+        return $this->post($this->preUrl . 'preorder', $body, $authorization);
+    }
+
+    //验签
+    public function signatureVerification($authorization, $body)
+    {
+        $authorization = str_replace($this->schema . " ", "", $authorization);
+        $authorization = str_replace(",", "&", $authorization);
+        $authorization = str_replace("\"", "", $authorization);
+        $authorization = $this->convertUrlQuery($authorization);
+
+        $authorization['signature'] = base64_decode($authorization['signature']);
+
+        $message = $authorization['timestamp'] . "\n" . $authorization['nonce_str'] . "\n" . $body . "\n";
+
+        $key = openssl_get_publickey(file_get_contents($this->lklCertificatePath));
+        $flag = openssl_verify($message, $authorization['signature'], $key, OPENSSL_ALGO_SHA256);
+        openssl_free_key($key);
+        if ($flag) {
+            return true;
+        }
+        return false;
+    }
+
+    //签名
+    public function getAuthorization($body)
+    {
+        $nonceStr = random(8);
+        $timestamp = time();
+
+        $message = $this->appid . "\n" . $this->mchSerialNo . "\n" . $timestamp . "\n" . $nonceStr . "\n" . $body . "\n";
+
+        $key = openssl_get_privatekey(file_get_contents($this->merchantPrivateKeyPath));
+
+        openssl_sign($message, $signature, $key, OPENSSL_ALGO_SHA256);
+        openssl_free_key($key);
+
+        return $this->schema . " appid=\"" . $this->appid . "\"," . "serial_no=\"" . $this->mchSerialNo . "\"," . "timestamp=\"" . $timestamp . "\"," . "nonce_str=\"" . $nonceStr . "\"," . "signature=\"" . base64_encode($signature) . "\"";
+    }
+
+    //请求
+    public function post($url, $data, $authorization)
+    {
+
+        $headers = [
+            "Authorization: " . $authorization,
+            "Accept: application/json",
+            "Content-Type:application/json",
+        ];
+
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//设置HTTP头
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        $res = curl_exec($ch);
+        curl_close($ch);
+
+        return json_decode($res, 1);
+    }
+
+    //签名参数转数组
+    private function convertUrlQuery($query)
+    {
+        $queryParts = explode('&', $query);
+
+        $params = array();
+        foreach ($queryParts as $param) {
+            $item = explode('=', $param);
+            $params[$item[0]] = $item[1];
+        }
+        if ($params['signature']) {
+            $params['signature'] = substr($query, strrpos($query, 'signature=') + 10);
+        }
+
+        return $params;
+    }
+
+}

+ 6 - 0
common/components/lakala/TermExtInfo.php

@@ -0,0 +1,6 @@
+<?php
+namespace common\components\lakala;
+
+class TermExtInfo {
+    public $termLoc;
+}

+ 21 - 0
vendor/lakala/cs_cert.cer

@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDYTCCAkmgAwIBAgIJAN+6gZTEG4TPMA0GCSqGSIb3DQEBCwUAMEkxCzAJBgNV
+BAYTAlVTMREwDwYDVQQIEwhzaGFuZ2hhaTERMA8GA1UEBxMIc2hhbmdoYWkxFDAS
+BgNVBAMUC2xha2FsYV8yMDIxMB4XDTIxMDYxODA3MjEzNFoXDTMxMDYxOTA3MjEz
+NFowSTELMAkGA1UEBhMCVVMxETAPBgNVBAgTCHNoYW5naGFpMREwDwYDVQQHEwhz
+aGFuZ2hhaTEUMBIGA1UEAxQLbGFrYWxhXzIwMjEwggEiMA0GCSqGSIb3DQEBAQUA
+A4IBDwAwggEKAoIBAQDvDBZyHUDndAGxrIcsCV2njhNO3vCEZotTaWYSYwtDvkcA
+b1EjsBFabXZaKigpqFXk5XXNI3NIHP9M8XKzIgGvc65NpLAfRjVql8JiTvLyYd1g
+IUcOXMInabu+oX7dQSI1mS8XzqaoVRhDZQWhXcJW9bxMulgnzvk0Ggw07AjGF7si
++hP/Va8SJmN7EJwfQq6TpSxR+WdIHpbWdhZ+NHwitnQwAJTLBFvfk28INM39G7XO
+sXdVLfsooFdglVTOHpNuRiQAj9gShCCNrpGsNQxDiJIxE43qRsNsRwigyo6DPJk/
+klgDJa417E2wgP8VrwiXparO4FMzOGK15quuoD7DAgMBAAGjTDBKMAkGA1UdEwQC
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