|
@@ -51,7 +51,58 @@ class Tenim
|
|
|
"Text"=> $message
|
|
|
],
|
|
|
];
|
|
|
- $tencentObj->toSend($data);
|
|
|
+ $res = $tencentObj->toSend($data);
|
|
|
+
|
|
|
+ if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
|
|
|
+ $error = !empty($res['ErrorInfo']) ? 'im error:'.$res['ErrorInfo'] : 'im error';
|
|
|
+ return $error;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送自定义消息给某人
|
|
|
+ */
|
|
|
+ public function sendCustomMessageToUser($from_user,$to_user,$message) {
|
|
|
+
|
|
|
+ $random = rand(10000000,99999999);
|
|
|
+ $usersig = $this->usersig("administrator");
|
|
|
+ // 获取配置信息
|
|
|
+ $config = config("tencent_im");
|
|
|
+ $url = "https://console.tim.qq.com/v4/openim/sendmsg";
|
|
|
+ $url .= "?sdkappid=".$config["sdkappid"];
|
|
|
+ $url .= "&identifier=administrator";
|
|
|
+ $url .= "&usersig=".$usersig;
|
|
|
+ $url .= "&random=".$random;
|
|
|
+ $url .= "&contenttype=json";
|
|
|
+ $tencentObj = new tencentim($url);
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+ $data["SyncOtherMachine"] = 1;//1=消息同步至发送方,2=消息不同步至发送方
|
|
|
+ $data["From_Account"] = (string)$from_user;
|
|
|
+ $data["To_Account"] = (string)$to_user;
|
|
|
+ $data["MsgRandom"] = rand(1000000,9999999);
|
|
|
+ $data["MsgTimeStamp"] = time();
|
|
|
+
|
|
|
+ $data["MsgBody"][] = [
|
|
|
+ "MsgType" => "TIMCustomElem",
|
|
|
+ "MsgContent" => [
|
|
|
+ "Data" => json_encode($message),
|
|
|
+ "Desc" => $message['name'],
|
|
|
+ "Ext" => $message['name'],
|
|
|
+ "Sound"=> '',
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $res = $tencentObj->toSend($data);
|
|
|
+
|
|
|
+ if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
|
|
|
+ $error = !empty($res['ErrorInfo']) ? 'im error:'.$res['ErrorInfo'] : 'im error';
|
|
|
+ return $error;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
|
|
|
}
|
|
|
|