| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- class Model_apittv1 extends Lin_Model {
- function __construct(){
- parent::__construct();
- $this->load->_model("Model_logic_ding","logic_ding");
- $this->load->_model("Model_apitt","apitt");
- }
- private function sign($method,$query,$body,$secret){
-
- unset($query['sign']);
- unset($query['access_token']);
- $input = $method;
- ksort($query);
- foreach ($query as $key => $value) {
- $input.= $key.$value;
- }
- if(!empty($body)){
- $input.= json_encode($body);
- }
- $input = $secret . $input . $secret;
- // 生成签名
- $sign = hash_hmac('sha256', $input,$secret);
- return $sign;
- }
-
- private function reqGet($url,$headers){
-
- // 初始化cURL
- $ch = curl_init();
-
- // 设置cURL选项
- curl_setopt_array($ch, [
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HTTPGET => true, // 明确设置为GET请求
- CURLOPT_HTTPHEADER => $headers,
-
- // SSL设置 - 禁用验证(仅测试环境)
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_SSL_VERIFYHOST => false,
-
- // 其他设置
- CURLOPT_TIMEOUT => 300,
- CURLOPT_FOLLOWLOCATION => true,
- ]);
-
- // 执行请求
- $response = curl_exec($ch);
-
- // 检查错误
- $error_msg = "";
- if (curl_errno($ch)) {
- $error_msg = $ch;
- }
-
- // 获取HTTP状态码
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- return [
- 'httpCode'=>$httpCode,
- 'response'=>$response,
- 'errorMsg'=>$error_msg
- ];
-
- }
- private function reqPost($url,$headers,$data){
- // 初始化cURL
- $ch = curl_init();
- // 设置cURL选项
- curl_setopt_array($ch, [
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POST => true,
- CURLOPT_HTTPHEADER => $headers,
- CURLOPT_POSTFIELDS => json_encode($data),
- CURLOPT_SSL_VERIFYPEER => false, // 根据实际情况调整,生产环境建议设为true
- CURLOPT_TIMEOUT => 300,
- ]);
- // 执行请求
- $response = curl_exec($ch);
- // 检查错误
- $error_msg = "";
- if (curl_errno($ch)) {
- $error_msg = curl_error($ch);
- }
- // 获取HTTP状态码
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- // 关闭cURL资源
- curl_close($ch);
- return [
- 'httpCode'=>$httpCode,
- 'response'=>$response,
- 'errorMsg'=>$error_msg
- ];
- }
- public function downloadLabel($package_id,$shop,$info){
- $url = 'https://open-api.tiktokglobalshop.com';
- $link = '/fulfillment/202309/packages/'.$package_id.'/shipping_documents';
- $time = time();
- $querys = [
- 'shop_cipher'=>$shop['shop_cipher'],
- 'app_key'=>$shop['app_key'],
- 'timestamp'=>$time,
- 'document_type'=>'SHIPPING_LABEL'
- ];
- echo "<pre>";
- $sign = $this->sign($link,$querys,[],$shop['app_key']);
- var_dump($sign);
-
- $link .= '?shop_cipher='.$shop['shop_cipher'].'&app_key='.$shop['app_key'].'×tamp='.$time."&document_type=SHIPPING_LABEL";
- $url = $url.$link;
- $headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
- $url .= $link.'&sign=';
- $sign = $this->apitt->sign($url,$shop['app_key'],'') ;
- var_dump($sign);
- $res = $this->apitt->su_curl('',$url,$headers,$date_type='json',$timeout=300,$httptype="GET");
-
- print_r($res);
- die;
-
- // $res = $this->reqGet($url,$headers);
- // if($res['httpCode'] != 200){
- // echo "<pre>";
- // print_r($res);
- // }else{
- // echo "<pre>";
- // print_r($res);
- // }
-
- }
-
- }
|