Sfoglia il codice sorgente

获取快递信息 秘钥加密

lvhao 6 mesi fa
parent
commit
c77b77932c

+ 16 - 5
core/CoreApp/controllers/Apiexpress.php

@@ -16,7 +16,7 @@ class Apiexpress extends Start_Controller {
        
         if($arg == 'search')
         {
-            $this->search($arg_array);
+            $this->search();
         }else{
             $this->_a();
         }
@@ -29,11 +29,15 @@ class Apiexpress extends Start_Controller {
      * @param $arg_array[0] string 请求店铺 
      * @param $arg_array[1] string 请求单号
      */
-    public function search($arg_array){
-        $shop = isset($arg_array[0])?$arg_array[0]:"";
-        $waybill_no = isset($arg_array[1])?$arg_array[1]:"";
+    public function search(){
+        $data = file_get_contents('PHP://input');
+		$data = json_decode($data, true);
+        $shop = isset($data['shop'])?$data['shop']:"";
+        $waybill_no = isset($data['waybill'])?$data['waybill']:"";
         
-        $time = isset($arg_array[2])?$arg_array[2]:0;
+        $time = isset($data['time'])?$data['time']:0;
+
+        $jiami_str = isset($data['key'])?$data['key']:"";
         
         $now_time = time();
         if(strlen( $time."") != 10){
@@ -47,9 +51,16 @@ class Apiexpress extends Start_Controller {
             die($this->logic_tools->ret_json(-1,"请求店铺异常"));
         }
         $shop_key = $this->logic_tools->getshopname($shop);
+        if(empty($jiami_str)){
+            die($this->logic_tools->ret_json(-1,"秘钥信息不存在"));
+        }
+        $jiemi_str = $this->logic_tools->toolsjiemi($jiami_str,$this->key,$this->iv);
         if(empty($shop_key)){
             die($this->logic_tools->ret_json(-1,"该店铺的秘钥不存在"));
         }
+        if($jiemi_str != $shop_key){
+            die($this->logic_tools->ret_json(-1,"该店铺的秘钥不正确"));
+        }
         if(empty($waybill_no)){
             die($this->logic_tools->ret_json(-1,"请求单号异常"));
         }

+ 17 - 5
core/CoreApp/models/Model_logic_tools.php

@@ -26,7 +26,7 @@ class Model_logic_tools extends Lin_Model {
    //根据shop 来判断是那个店铺 到时间直接选中表就好
    function getshopname($shop){
         $arr =  [
-           // 3=>"alipearlhair",
+            3=>"alipearlhair",
             4=>"westkis"
         ];
         if(!isset($arr[$shop])){
@@ -56,15 +56,27 @@ class Model_logic_tools extends Lin_Model {
     * 对外通信的加密工具类
     *$decrypt 要加密内容
     */
-   function toolsjiami($decrypt){
-     return openssl_encrypt($decrypt,'AES-128-CBC',$this->key,0,$this->iv);
+   function toolsjiami($decrypt,$key = "",$iv = ""){
+     if(empty($key)){
+        $key = $this->key;
+     }
+     if(empty($iv)){
+        $iv = $this->iv;
+     }
+     return openssl_encrypt($decrypt,'AES-128-CBC',$key,0,$iv);
 
    }
    /**
     * 对外通信的解密工具类
     *$encrypt 要解密内容
    */
-   function toolsjiemi($encrypt){
-        return openssl_decrypt($encrypt,'AES-128-CBC',$this->key,0,$this->iv);
+   function toolsjiemi($encrypt,$key,$iv){
+        if(empty($key)){
+            $key = $this->key;
+        }
+        if(empty($iv)){
+            $iv = $this->iv;
+        }
+        return openssl_decrypt($encrypt,'AES-128-CBC',$key,0,$iv);
    }
 }