1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\api\controller;
- use think\facade\Request;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class ZskkDefaultApiController extends ZskkDefaultController {
- protected $needToken = false;
- protected $logName = "ZskkDefaultApiController";
- protected function afterSetRequest() {
- $this->setParams(Request::param(false));
- }
- function curlPost($url, $data) {
- //初使化init方法
- $ch = curl_init();
- //指定URL
- curl_setopt($ch, CURLOPT_URL, $url);
- //设定请求后返回结果
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- //声明使用POST方式来进行发送
- curl_setopt($ch, CURLOPT_POST, 1);
- //发送什么数据呢
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- //忽略证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- //忽略header头信息
- curl_setopt($ch, CURLOPT_HEADER, 0);
- //设置超时时间
- // curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- //发送请求
- $output = curl_exec($ch);
- //关闭curl
- curl_close($ch);
- //返回数据
- return $output;
- }
- public function getDecryptData($data)
- {
- $key = 'zLxapoeqWYpoeqWY';
- $info = $this->decrypt($key,$data);
- if(empty($info))
- {
- return '数据解析失败';
- }else{
- $arr = json_decode(base64_decode($info),true);
- if(empty($arr))
- {
- return '数据解析失败,失败原因:数据加密前未进行base64转换';
- }
- return $arr;
- }
- }
- public static function encrypt($key, $str)
- {
- if($str) {
- $iv = str_repeat("\0", openssl_cipher_iv_length('SM4-CBC'));
- $ciphertext = openssl_encrypt($str, 'SM4-CBC', $key, OPENSSL_RAW_DATA, $iv);
- return base64_encode($ciphertext);
- }
- return $str;
- }
- /*
- * 国密4解密
- * str 解密字符串
- */
- public static function decrypt($key, $str)
- {
- if($str) {
- $iv = str_repeat("\0", openssl_cipher_iv_length('SM4-CBC'));
- return openssl_decrypt(base64_decode($str), 'SM4-CBC', $key, OPENSSL_RAW_DATA, $iv);
- }
- return $str;
- }
- }
|