|
@@ -0,0 +1,83 @@
|
|
|
+<?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'=>$admin['username'],
|
|
|
+ '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['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'],
|
|
|
+ ];
|
|
|
+ $json=$this->post('https://qiyukf.com/openapi/kefu/update',$data);
|
|
|
+ if($json['code']!==200){
|
|
|
+ throw_user('修改失败'.$json['message']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|