作者 何书鹏
1 个管道 的构建 通过 耗费 0 秒

api更新

... ... @@ -9,6 +9,7 @@ use app\api\model\DoctorNowork;
use app\api\model\Withdraw;
use app\common\controller\Api;
use app\api\model\Doctor as DoctorModel;
use app\common\controller\Tim;
use app\common\controller\Wechat;
use think\Db;
use think\Exception;
... ... @@ -184,7 +185,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (87)
* @ApiWeigh (93)
* @ApiTitle (预约-确认完成)
* @ApiSummary (预约-确认完成)
* @ApiMethod (POST)
... ... @@ -206,7 +207,46 @@ class Doctor extends Api
}
/**
* @ApiWeigh (95)
* @ApiWeigh (91)
* @ApiTitle (在线咨询)
* @ApiSummary (在线咨询)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=appointment_id, type=integer, required=true, description="预约ID")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1604282876",
"data": null
})
*/
public function diagnose(){
$appointment_id = $this->request->post('appointment_id');
empty($appointment_id) && $this->error('缺少必需参数');
$appointment = Appointment::get(['doctor_id'=>$this->id,'id'=>$appointment_id]);
empty($appointment) && $this->error('预约不存在');
!in_array($appointment['status'],'1,2') && $this->error('订单不合法');
if($appointment['status'] == '1'){
$tim = new Tim();
// 导入用户
if(!$res = $tim->importUser($appointment['user'])){
$this->error($tim->getError());
}
// 导入医生
if(!$res = $tim->importUser($appointment['doctor'])){
$this->error($tim->getError());
}
// 发送消息
if(!$res = $tim->sendMsg('doctor_'.$appointment['doctor_id'],'user_'.$appointment['user_id'],'服务开始,请问有什么可以帮助您的?')){
$this->error($tim->getError());
}
$appointment->save(['status'=>'2','diagnose_time'=>time()]);
}
$this->success('成功');
}
/**
* @ApiWeigh (89)
* @ApiTitle (个人信息)
* @ApiSummary (个人信息)
* @ApiMethod (POST)
... ... @@ -242,7 +282,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (93)
* @ApiWeigh (87)
* @ApiTitle (修改信息)
* @ApiSummary (修改信息)
* @ApiMethod (POST)
... ... @@ -273,7 +313,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (91)
* @ApiWeigh (85)
* @ApiTitle (我的收益)
* @ApiSummary (我的收益)
* @ApiMethod (POST)
... ... @@ -300,7 +340,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (89)
* @ApiWeigh (83)
* @ApiTitle (我的收益-明细)
* @ApiSummary (我的收益-明细)
* @ApiMethod (POST)
... ... @@ -345,7 +385,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (87)
* @ApiWeigh (81)
* @ApiTitle (提现)
* @ApiSummary (提现)
* @ApiMethod (POST)
... ... @@ -405,7 +445,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (85)
* @ApiWeigh (79)
* @ApiTitle (预约时间)
* @ApiSummary (预约时间)
* @ApiMethod (POST)
... ... @@ -444,7 +484,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (83)
* @ApiWeigh (77)
* @ApiTitle (预约时间-不接诊)
* @ApiSummary (预约时间-不接诊)
* @ApiMethod (POST)
... ... @@ -482,7 +522,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (81)
* @ApiWeigh (75)
* @ApiTitle (我的评价)
* @ApiSummary (我的评价)
* @ApiMethod (POST)
... ... @@ -543,7 +583,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (79)
* @ApiWeigh (73)
* @ApiTitle (我的评价-回复)
* @ApiSummary (我的评价-回复)
* @ApiMethod (POST)
... ... @@ -570,7 +610,7 @@ class Doctor extends Api
}
/**
* @ApiWeigh (77)
* @ApiWeigh (71)
* @ApiTitle (我的评价-申请删除)
* @ApiSummary (我的评价-申请删除)
* @ApiMethod (POST)
... ...
... ... @@ -781,7 +781,7 @@ class User extends Api
})
*/
public function getTimSig(){
$usersig = (new Tim)->getSig($this->auth->id);
$usersig = (new Tim)->getSig('user_'.$this->auth->id);
$this->success('成功',compact('usersig'));
}
... ... @@ -808,4 +808,43 @@ class User extends Api
$this->error($this->auth->getError());
}
}
/**
* @ApiWeigh (75)
* @ApiTitle (在线咨询)
* @ApiSummary (在线咨询)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=appointment_id, type=integer, required=true, description="预约ID")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1604282876",
"data": null
})
*/
public function diagnose(){
$appointment_id = $this->request->post('appointment_id');
empty($appointment_id) && $this->error('缺少必需参数');
$appointment = Appointment::get(['user_id'=>$this->auth->id,'id'=>$appointment_id]);
empty($appointment) && $this->error('预约不存在');
!in_array($appointment['status'],'1,2') && $this->error('订单不合法');
if($appointment['status'] == '1'){
$tim = new Tim();
// 导入用户
if(!$res = $tim->importUser($appointment['user'])){
$this->error($tim->getError());
}
// 导入医生
if(!$res = $tim->importUser($appointment['doctor'])){
$this->error($tim->getError());
}
// 发送消息
if(!$res = $tim->sendMsg('doctor_'.$appointment['doctor_id'],'user_'.$appointment['user_id'],'服务开始,请问有什么可以帮助您的?')){
$this->error($tim->getError());
}
$appointment->save(['status'=>'2','diagnose_time'=>time()]);
}
$this->success('成功');
}
}
... ...
... ... @@ -11,6 +11,8 @@ class Tim extends Controller
protected $key;
protected $api;
protected $identifier = 'administrator';
// 错误信息
protected $_error = '';
public function __construct(){
vendor('autoload');
... ... @@ -42,6 +44,62 @@ class Tim extends Controller
return json_decode($response,true);
}
/**
* 导入用户账号
*/
public function importUser($user){
//导入腾讯im账号(先查询是否存在,不存在就导入)
$portrait_get_res = $this->portraitGet('user_'.$user['user_id']);//查询
if(!isset($portrait_get_res['ErrorCode'])){
$this->setError('拉取资料接口报错');
return false;
}
if($portrait_get_res['ErrorCode'] != 0 && $portrait_get_res['ErrorCode'] != 40003){
$this->setError($portrait_get_res['ErrorInfo']);
return false;
}
if($portrait_get_res['UserProfileItem'][0]['ResultCode'] == 40003){
$import_res = $this->accountImport('user_'.$user['id'],$user['nickname'],$user['avatar']);//导入
if(!isset($import_res['ErrorCode'])){
$this->setError('导入账号失败');
return false;
}
if($import_res['ErrorCode'] != 0){
$this->setError($import_res['ErrorInfo']);
return false;
}
}
return true;
}
/**
* 导入医生账号
*/
public function importDoctor($doctor){
//导入腾讯im账号(先查询是否存在,不存在就导入)
$portrait_get_res = $this->portraitGet('doctor_'.$doctor['id']);//查询
if(!isset($portrait_get_res['ErrorCode'])){
$this->setError('拉取资料接口报错');
return false;
}
if($portrait_get_res['ErrorCode'] != 0 && $portrait_get_res['ErrorCode'] != 40003){
$this->setError($portrait_get_res['ErrorInfo']);
return false;
}
if($portrait_get_res['UserProfileItem'][0]['ResultCode'] == 40003){
$import_res = $this->accountImport('doctor_'.$doctor['id'],$doctor['nickname'],$doctor['avatar']);//导入
if(!isset($import_res['ErrorCode'])){
$this->setError('导入账号失败');
return false;
}
if($import_res['ErrorCode'] != 0){
$this->setError($import_res['ErrorInfo']);
return false;
}
}
return true;
}
/**
* 帐号删除
*/
... ... @@ -57,10 +115,12 @@ class Tim extends Controller
$response = $client->request('POST',$url,$data);
$res = json_decode($response,true);
if(!isset($res['ErrorCode'])){
exception('帐号删除失败',200);
$this->setError('帐号删除失败');
return false;
}
if($res['ErrorCode'] != 0){
exception($res['ErrorInfo'],200);
$this->setError($res['ErrorInfo']);
return false;
}
}
... ... @@ -98,12 +158,12 @@ class Tim extends Controller
$response = $client->request('POST',$url,$data);
$res = json_decode($response,true);
if(!isset($res['ErrorCode'])){
Db::rollback();
exception('加好友失败',200);
$this->setError('加好友失败');
return false;
}
if($res['ErrorCode'] != 0){
Db::rollback();
exception($res['ErrorInfo'],200);
$this->setError($res['ErrorInfo']);
return false;
}
}
... ... @@ -121,7 +181,7 @@ class Tim extends Controller
]);
$client = new Client();
$response = $client->request('POST',$url,$data);
halt($response);
return json_decode($response,true);
}
/**
... ... @@ -139,24 +199,25 @@ class Tim extends Controller
$response = $client->request('POST',$url,$data);
$res = json_decode($response,true);
if(!isset($res['ErrorCode'])){
Db::rollback();
exception('删除好友失败',200);
$this->setError('删除好友失败');
return false;
}
if($res['ErrorCode'] != 0){
Db::rollback();
exception($res['ErrorInfo'],200);
$this->setError($res['ErrorInfo']);
return false;
}
}
/**
* 发送信息
*/
public function sendMsg($user_id,$msg){
public function sendMsg($user_id1,$user_id2,$msg){
$usersig = $this->getSig($this->identifier);
$url = "https://console.tim.qq.com/v4/openim/sendmsg?sdkappid={$this->sdkappid}&identifier={$this->identifier}&usersig={$usersig}&random=99999999&contenttype=json";
$data = json_encode([
'SyncOtherMachine' => 2,
'To_Account' => (string)$user_id,
'From_Account' => (string)$user_id1,
'To_Account' => (string)$user_id2,
'MsgLifeTime' => 60,
'MsgRandom' => 1287657,
'MsgTimeStamp' => 1557387418,
... ... @@ -171,6 +232,48 @@ class Tim extends Controller
]);
$client = new Client();
$response = $client->request('POST',$url,$data);
halt($response);
$res = json_decode($response,true);
if(!isset($res['ErrorCode'])){
$this->setError('发送信息失败');
return false;
}
if($res['ErrorCode'] != 0){
$this->setError($res['ErrorInfo']);
return false;
}
}
/**
* 查询单聊未读消息计数
*/
public function getNoreadMsgNum($user_id1,$user_id2){
$usersig = $this->getSig($this->identifier);
$url = "https://console.tim.qq.com/v4/openim/sendmsg?sdkappid={$this->sdkappid}&identifier={$this->identifier}&usersig={$usersig}&random=99999999&contenttype=json";
$data = json_encode([
"To_Account" => (string)$user_id1,
"Peer_Account" => [
(string)$user_id2,
]
]);
$client = new Client();
$response = $client->request('POST',$url,$data);
return json_decode($response,true);
}
/**
* 设置错误信息
*/
public function setError($error)
{
$this->_error = $error;
return $this;
}
/**
* 获取错误信息
*/
public function getError()
{
return $this->_error ? __($this->_error) : '';
}
}
... ...
此 diff 太大无法显示。