app_key = '817267c4c2f3476b863522525b97ac78'; $this->app_secret = '559f778b1b4f4e47b0265fa5fbedfb54'; $this->httpClient=new Client([ 'http_errors' => false ]); } public function pullData(Request $request) { $log = [ 'content' => json_encode($request->all()), ]; HukeCallback::create($log); } public function get_customer_fields($update = false) { if(!$update){ if(Cache::has("huke_customer_fields")){ return Cache::get("huke_customer_fields"); } } $params = []; $params = json_encode($params); $appSecret = substr(openssl_digest(openssl_digest($this->app_secret, 'sha1', true), 'sha1', true), 0, 16); $time = time(); $sign = md5($params); $checksum = bin2hex(openssl_encrypt($this->app_key. $sign. $time, 'AES-128-ECB', $appSecret, OPENSSL_RAW_DATA)); $headers = [ 'Content-Type' => 'application/json', 'ur-appkey' => $this->app_key, 'ur-sign' => $sign, 'ur-curtime' => $time, 'ur-checksum' => $checksum ]; $response = $this->httpClient->post('https://huke.163.com/openapi/customer/fields', ['body'=>$params,'headers' => $headers]); $res = json_decode($response->getBody()->getContents(),true); $fields = []; foreach ($res['data'] as $k => $v){ $fields[$v['id']] = $v; } Cache::put('huke_customer_fields',$fields,'86400'); return $fields; } public function get_customer_list($start,$end,$page,$page_size) { $params = [ 'startTime' => str_pad(strtotime($start),13,'0',STR_PAD_RIGHT), 'endTime' => str_pad(strtotime($end),13,'0',STR_PAD_RIGHT), 'page'=>$page, 'pageSize'=>$page_size ]; $params = json_encode($params); $appSecret = substr(openssl_digest(openssl_digest($this->app_secret, 'sha1', true), 'sha1', true), 0, 16); $time = time(); $sign = md5($params); $checksum = bin2hex(openssl_encrypt($this->app_key. $sign. $time, 'AES-128-ECB', $appSecret, OPENSSL_RAW_DATA)); $headers = [ 'Content-Type' => 'application/json', 'ur-appkey' => $this->app_key, 'ur-sign' => $sign, 'ur-curtime' => $time, 'ur-checksum' => $checksum ]; $response = $this->httpClient->post('https://huke.163.com/openapi/customer/list', ['body'=>$params,'headers' => $headers]); $res = json_decode($response->getBody()->getContents(),true); dd($res); } public function test() { $res = $this->get_customer_fields(); $params = [ 'type' => 0, 'targets' => [ '15759560669' ] ]; $params = json_encode($params); $appSecret = substr(openssl_digest(openssl_digest($this->app_secret, 'sha1', true), 'sha1', true), 0, 16); $time = time(); $sign = md5($params); $checksum = bin2hex(openssl_encrypt($this->app_key. $sign. $time, 'AES-128-ECB', $appSecret, OPENSSL_RAW_DATA)); $headers = [ 'Content-Type' => 'application/json', 'ur-appkey' => $this->app_key, 'ur-sign' => $sign, 'ur-curtime' => $time, 'ur-checksum' => $checksum ]; $response = $this->httpClient->post('https://huke.163.com/openapi/customer/query', ['body'=>$params,'headers' => $headers]); $res = json_decode($response->getBody()->getContents(),true); dd($res); } }