|
@@ -181,6 +181,88 @@ class Tenim
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * IM添加好友
|
|
|
+ */
|
|
|
+ public function friend_add($From_Account,$To_Account){
|
|
|
+ $random = rand(10000000,99999999);
|
|
|
+ $usersig = $this->usersig("administrator");
|
|
|
+ // 获取配置信息
|
|
|
+ $config = config("tencent_im");
|
|
|
+ $url = "https://console.tim.qq.com/v4/sns/friend_add";
|
|
|
+ $url .= "?sdkappid=".$config["sdkappid"];
|
|
|
+ $url .= "&identifier=administrator";
|
|
|
+ $url .= "&usersig=".$usersig;
|
|
|
+ $url .= "&random=".$random;
|
|
|
+ $url .= "&contenttype=json";
|
|
|
+ $tencentObj = new tencentim($url);
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'From_Account' => $From_Account,
|
|
|
+ 'AddFriendItem' => [
|
|
|
+ [
|
|
|
+ 'To_Account' => $To_Account,
|
|
|
+ 'AddSource' => 'AddSource_Type_APP',
|
|
|
+
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ 'AddType' => 'Add_Type_Both',
|
|
|
+ 'ForceAddFlags' => 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $res = $tencentObj->toSend($data);
|
|
|
+
|
|
|
+ if (isset($res['ActionStatus']) && $res['ActionStatus'] == 'OK') {
|
|
|
+ if( isset($res['ResultItem'][0]['ResultCode'])
|
|
|
+ && isset($res['ResultItem'][0]['To_Account'])
|
|
|
+ && $res['QueryResult'][0]['ResultCode'] == 0
|
|
|
+ && $res['QueryResult'][0]['To_Account'] == $To_Account){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * IM删除好友
|
|
|
+ */
|
|
|
+ public function friend_del($From_Account,$To_Account){
|
|
|
+ $random = rand(10000000,99999999);
|
|
|
+ $usersig = $this->usersig("administrator");
|
|
|
+ // 获取配置信息
|
|
|
+ $config = config("tencent_im");
|
|
|
+ $url = "https://console.tim.qq.com/v4/sns/friend_delete";
|
|
|
+ $url .= "?sdkappid=".$config["sdkappid"];
|
|
|
+ $url .= "&identifier=administrator";
|
|
|
+ $url .= "&usersig=".$usersig;
|
|
|
+ $url .= "&random=".$random;
|
|
|
+ $url .= "&contenttype=json";
|
|
|
+ $tencentObj = new tencentim($url);
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'From_Account' => $From_Account,
|
|
|
+ 'To_Account' => [
|
|
|
+ $To_Account,
|
|
|
+ ],
|
|
|
+ 'DeleteType' => 'Delete_Type_Both',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $res = $tencentObj->toSend($data);
|
|
|
+
|
|
|
+ if (isset($res['ActionStatus']) && $res['ActionStatus'] == 'OK') {
|
|
|
+ if( isset($res['ResultItem'][0]['ResultCode'])
|
|
|
+ && isset($res['ResultItem'][0]['To_Account'])
|
|
|
+ && $res['QueryResult'][0]['ResultCode'] == 0
|
|
|
+ && $res['QueryResult'][0]['To_Account'] == $To_Account){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取usersig签名-具体操作
|