hrjy hace 2 años
padre
commit
e302f4bfed
Se han modificado 1 ficheros con 29 adiciones y 31 borrados
  1. 29 31
      crmeb/services/GmService.php

+ 29 - 31
crmeb/services/GmService.php

@@ -29,7 +29,7 @@ class GmService
     protected static $iv = 'abcdefghABCDEFGH';
     protected static $appID = "3f1a51c1-39d4-48e1-8119-a37b63c0ed8c";
     protected static $appSecretKey = "66a81e7a-dea3-4870-9c63-58712e13aa9b";
-    protected static $tokenUrl = "https://mouldai.com/api/HOGENDY";//回归环境
+    protected static $tokenUrl = "https://tlop.zjtlcb.com/api/HOGENDY";//回归环境
     protected static $token;
     //合作机构自有公钥
     const PUBLIC_KEY = "DE3w4DgjV+np0oHQzSDUgvlxGKPhi/gHBRp8dtjun+z6uqrRJE6B1qswZpaSCs3tp0tm98ZjjL9RTuNh4dyUuA==";
@@ -63,25 +63,23 @@ class GmService
     //获取token
     public static function getToken()
     {
-
-        self::_initialize();
         //获取6位数字符串
         $seqNO = (string)rand(100000, 999999);
         //获取16位随机字符串并md5 转大写 得到
         $key = strtoupper(md5(self::getKey()));
 
 
-//        echo self::string2hex(base64_decode(self::PRIVATE_KEY));
-//
+        //echo $this->string2hex(base64_decode(self::PRIVATE_KEY));
+
 //        echo self::string2hex(base64_decode(self::PUBLIC_KEY));
 
-//        //初始化转换密钥信息
+
+        //初始化转换密钥信息
         php_HextoAsc(self::string2hex(base64_decode(self::PRIVATE_KEY)), $k1);
         php_HextoAsc(self::string2hex(base64_decode(self::PUBLIC_KEY)), $k2);
         php_HextoAsc(self::string2hex(base64_decode(self::CGB_PUBLIC_KEY)), $gf_k);
-//        dump(12131243123212341);
-//        exit;
-//        //拼接参数数组
+
+        //拼接参数数组
         $data = [
             'appID' => self::$appID,
             'seqNO' => $seqNO,
@@ -89,24 +87,21 @@ class GmService
             'sm2EncryptData' => self::SM2Encrypt($key, $gf_k), //sm2加密key
             'sm2Sign' => self::SM2Sign($key, $k2, $k1), //sm2加密key
         ];
-        dump($data);
-        exit;
+
         //拼接签名参数,md5转大写
         $data['sign'] = self::SM3Crypt($data['random'] . $data['seqNO'] . self::$appSecretKey . $key);
 
-        dump($data);
-        exit;
-//        //发送post接口请求
-//        $res = self::https_post(self::$tokenUrl, $data);
-//        halt($res);
-//        exit();
-//
-//        //解密返回token数据
-//        $token = self::SM2Decrypt(base64_decode($res['sm2EncryptData']), $k1);
-//
-//        self::$token = $token;
-//        //返回token
-//        return $token;
+//        dump($data);
+//        exit;
+        //发送post接口请求
+        $res = self::https_post(self::$tokenUrl, $data);
+
+        //解密返回token数据
+        $token = self::SM2Decrypt(base64_decode($res['sm2EncryptData']), $k1);
+
+        self::$token = $token;
+        //返回token
+        return $token;
     }
 
     //业务请求数据
@@ -229,16 +224,19 @@ class GmService
     public static function SM2Encrypt($data, $pubkey)
     {
         //sm2加密
-        php_SM2Encrypt($data, $cipher, $pubkey);
-        dump(function_exists('php_SM2Encrypt'));
-        dump($cipher);
-        exit;
+        $recode = php_SM2Encrypt($data, $cipher, $pubkey);
+
+        echo "<br/>recode:$recode \n";
+
         //php_SM2Encrypt接口返回的密文值是c1c3c2格式,以下示例转DER编码
-        php_SM2FormatConvert(102, $cipher, $der);
-        dump($der);
-        exit;
+        $recode = php_SM2FormatConvert(102, $cipher, $der);
+        echo "<br/>recode:$recode \n";
+
         //SM2加密字符串转base64编码
         $sm2encrypted = base64_encode($der);
+
+        echo "<br/>sm2加密字符串base64:$sm2encrypted \n";
+
         return $sm2encrypted;
     }