xieruidong 2 years ago
parent
commit
afb0aa6049

+ 2 - 0
application/admin/controller/Index.php

@@ -6,6 +6,7 @@ use app\admin\model\Admin;
 use app\admin\model\AdminLog;
 use app\common\controller\Backend;
 use app\common\library\Sms;
+use app\common\service\Qiyu;
 use think\Config;
 use think\Hook;
 use think\Validate;
@@ -51,6 +52,7 @@ class Index extends Backend
         $this->view->assign('fixedmenu', $fixedmenu);
         $this->view->assign('referermenu', $referermenu);
         $this->view->assign('title', __('Home'));
+        dd(Qiyu::instance()->login($this->admin()));
         return $this->view->fetch();
     }
 

+ 1 - 0
application/admin/view/index/index.html

@@ -52,5 +52,6 @@
 
         <!-- 加载JS脚本 -->
         {include file="common/script" /}
+        <script></script>
     </body>
 </html>

+ 83 - 0
application/common/service/Qiyu.php

@@ -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;
+    }
+}