1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace app\common\service;
- /*
- * 223c300175fbea7b5f6ca4465ac6071f
- * 4D4EED8859E646DFA3BFB79B73075914
- *
- * */
- use app\admin\model\Admin;
- use GuzzleHttp\Client;
- use traits\think\Instance;
- class Qiyu{
- use Instance;
- protected $appKey='223c300175fbea7b5f6ca4465ac6071f';
- protected $appSecret='4D4EED8859E646DFA3BFB79B73075914';
- public function login(Admin $admin){
- $data=[
- 'staffName'=>$admin['username'],
- ];
- $json=$this->post('http://qiyukf.com/openapi/staff/login',$data);
- return $json['result']['sdk_url']??null;
- }
- /**
- * 普通客服 12762328
- */
- public function create(Admin $admin,$password){
- $data=[
- 'username'=>"service{$admin['id']}",
- 'password'=>md5($password),
- 'role'=>0,
- 'subRoleId'=>$admin['is_seller']?12764513:12767377,
- 'realname'=>$admin['nickname'],
- 'nickname'=>$admin['nickname'],
- 'mobile'=>$admin['mobile'],
- 'email'=>$admin['email']??'',
- ];
- $json=$this->post('https://qiyukf.com/openapi/kefu/add',$data);
- if($json['code']!==200){
- throw_user('['.$json['code'].']'.$json['message']);
- }
- return $json['id'];
- }
- /**
- * 销售 12764513
- * 管理 12767377
- */
- public function update(Admin $admin,$password){
- $data=[
- 'id'=>$admin['kf_id'],
- 'password'=>md5($password),
- 'role'=>0,
- 'subRoleId'=>$admin['is_seller']?12764513:12767377,
- 'realname'=>$admin['nickname'],
- 'nickname'=>$admin['nickname'],
- 'mobile'=>$admin['mobile'],
- 'email'=>$admin['email'],
- ];
- if(!$password){
- unset($data['password']);
- }
- $json=$this->post('https://qiyukf.com/openapi/kefu/update',$data);
- if($json['code']!==200){
- throw_user('修改失败'.$json['message']);
- }
- }
- public function delete(Admin $admin){
- if($admin['kf_id']){
- $data=[
- 'id'=>$admin['kf_id'],
- ];
- $this->post('https://qiyukf.com/openapi/kefu/delete',$data);
- }
- }
- protected function sum($data){
- $res=sha1(sprintf('%s%s%d',$this->appSecret,md5(json_encode($data)),$time=time()));
- return [$res,$time];
- }
- protected function post($url,$data){
- list($sum,$time)=$this->sum($data);
- $res=(new Client)
- ->post("$url?appKey={$this->appKey}&checksum={$sum}&time={$time}",[
- 'json'=>$data,
- ]);
- $json=json_decode($res->getBody()->getContents(),true);
- return $json;
- }
- }
|