123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace App\Http\Controllers\Api\Third;
- use App\Http\Controllers\Api\ApiBaseController;
- use Illuminate\Http\Request;
- use GuzzleHttp\Client;
- use Illuminate\Support\Facades\Cache;
- use App\Models\HukeCallback;
- class ScrmController extends ApiBaseController
- {
- /**
- * @var Client
- */
- private $httpClient;
- private $app_key;
- private $app_secret;
- /**
- * SmsService constructor.
- * @param $app_key
- * @param $app_secret
- * @param $sign_key
- */
- public function __construct()
- {
- $this->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);
- }
- }
|