0.0.6 • Published 4 years ago

@forchange/wind-sdk v0.0.6

Weekly downloads
7
License
ISC
Repository
-
Last release
4 years ago

@forchange/wind-sdk

npm version

风声 wind-web SDK

Install

$ npm install @forchange/wind-sdk

or

$ yarn add  @forchange/wind-sdk

Usage

import windSDK from "@forchange/wind-sdk";
import { ISocketResponseData } from "@forchange/wind-sdk/dist/modules/socket/type";

/**
 * @params account(必填) SDK(IM) 账号
 * @params password(必填) SDK(IM) 密码
 * @params url 所有接口(必填)(webSocket 除外)调用的地址
 *
 */
// 调用 getInstance 方法注册获得实例(无论失败成功一定会返回实例)
const SDK = windSDK.getInstance({
  url: "https://base.pandateacher.com/",
  account: "123",
  password: "456",
  // 登录成功
  onSuccess: res => {
    console.log(res);
  },
  // 登录失败
  onError: error => {
    console.log(error);
  }
});

webSocket(推送服务)

/**
 * @params state 当前的链接状态 等效于  WebSocket.readyState
 * @params data 为服务器返回的数据
 */
const onmessage = (state: number, data: ISocketResponseData) => {
  console.log("服务器的消息: ", data.data);
};
const ws = new SDK.Socket({
  url: "ws://localhost:8084/", // ws地址
  onmessage: onmessage, // 从服务器接受到信息时的回调函数
  onopen: (state: number, event?: Event) => {}, // 指定连接成功后的回调函数
  onerror: (state: number, event?: Event) => {}, // 指定连接失败后的回调函数
  onclose: (state: number, event?: CloseEvent) => {} // 指定连接关闭后的回调函数
});
ws.connect(); // 连接ws
ws..onHandClose() // 关闭ws
// 发送ws
 ws.connected()
.then((websocket: Socket) => {
    websocket.sendData('send message').then((wt: Socket) => {})
    }).catch(err => {console.error( err)})

下面列子为 SDK (webSocket 除外,参考上面)的调用统一形式(后面统一使用这种形式,不再赘余)

SDK.login({ account: "1", password: "2" })
  .then(res => {
    // status	number 返回状态,接口返回码等于0表示SDK错误
  })
  .catch(error => {
    //  失败
  });

chats(消息)

  1. 下载消息文件
/**
 * @description 下载消息文件
 * @params downType	number 1:下载视频封面/图片文件/语音(视频封面图:只下载视频的第一帧图片)2:下载视频 3:下载视频和视频封面) 0:其他类型
 * @params fileCode	string 文件编号
 * @params frn	string 风声信息来源识别码,默认(opdns)
 * @params ope	number 账户号
 * 账户号
 */
SDK.chats.chatsDownload({
  downType: 0,
  fileCode: "string",
  frn: "opdns",
  ope: 16420
});
  1. 群消息发送(在群内发送信息,以{ProfileId}发送给{GroupId})
SDK.chats.chatsGroup({
  frn: "opdns", // 风声信息来源识别码,默认(opdns)
  groupId: 0, // 群id
  isAt: 0, // 是否艾特(0:艾特群内所有人;1:艾特或者不艾特用户)
  msg: [
    {
      content: "string", // 文字内容
      desc: "string", //链接描述
      ext: "amr", // 语音消息格式
      md5: "string", // 文件的md5值
      mediaTime: 0, // 语音时长/视频时长
      msgTime:number, // 发送时间
      msgType: 1, // 消息类型(1:文字;2:图片;3:语音;4:视频;5:链接;6:好友名片;7:文件;8:小程序;9:音乐)
      num: 0, // 消息编号(整型,用于区分同一组的消息)
      size: 3232, // 语音文件大小,以Byte为单位
      title: "string", // 链接标题
      url: "string" // 链接URL,当消息为视频时,此处传视频的链接地址
    }
  ],
  ope: 16420, // 账户号
  profileId: 0 // 用户ID
});
  1. 私聊发消息(私聊好友发送消息,以{ProfileId}发送给{FriendId})
SDK.chats.chatsGroup({
  friendId: 0,
  frn: "opdns",
  msg: [
    {
      content: "string",
      desc: "string",
      ext: "amr",
      md5: "string",
      mediaTime: 0,
      msgTime: "string",
      msgType: 1,
      num: 0,
      size: 3232,
      title: "string",
      url: "string"
    }
  ],
  ope: 16420,
  profileId: 0
});

group(群)

  1. 群内主动添加好友
SDK.group.groupAdd({
  friendId: 333, // 好友ID
  groupId: 444, // 群Id
  helloWord: "55555", //打招呼(必填-例如:我是XXX)
  frn: "444",
  ope: 5555
});
  1. 群管理设置
SDK.group.groupAdmin({
  adminIds: [0], // 被设置为管理员或被移除管理员的编号
  groupId: 0, // 群ID
  opn: 1, // 操作(1:新增;0:移除)
  frn: "opdns",
  ope: 16420
});
  1. 通过好友群邀请
SDK.group.groupAdoptInvite({
  act: "string", // 操作编号
  frn: "opdns",
  ope: 16420
});
  1. 撤销邀请好友入群
SDK.group.groupCancelInvite({
  friendId: [0], // 好友ID最少一个
  groupId: 0, // 群Id
  frn: "opdns",
  ope: 16420
});
  1. 获取保存至通讯录的群
SDK.group.groupContacts({
  frn: "opdns",
  ope: 16420
});
  1. 创建群
SDK.group.groupCreate({
  friends: [0], // 创建群被拉成员id
  frn: "opdns",
  name: "string", // 群名称
  ope: 16420
});
  1. 群内踢人
SDK.group.groupDelete({
  friendId: 0, // 好友ID
  groupId: 0, // 群ID
  frn: "opdns",
  ope: 16420
});
  1. 主动退群异步调用
SDK.group.groupLeave({
  frn: "opdns",
  groupId: 0,
  ope: 16420
});
  1. 获取群列表
SDK.group.groupList({
  frn: "opdns",
  isOpenMessage: "string", // 是否已开通(10 是 11 否)
  ope: 16420
});
  1. 修改群名称
SDK.group.groupName({
  frn: "opdns",
  groupId: 0, // 群Id
  name: "string", // 群名称
  ope: 16420
});
  1. 设置群内昵称异步调用
SDK.group.groupNickname({
  frn: "opdns",
  groupId: 0,
  name: "string", // 群内名称
  ope: 16420
});
  1. 群发布公告
SDK.group.groupNotice({
  content: "string", // 公告内容
  frn: "opdns",
  groupId: 0,
  ope: 16420
});
  1. 群发布公告异步调用
SDK.group.groupNoticeRead({
  frn: "opdns",
  groupId: 0,
  ope: 16420
});
  1. 查询群聊验证状态
SDK.group.groupOpenVerify({
  frn: "opdns",
  groupId: 0,
  ope: 16420
});
  1. 获取群二维码异步调用
SDK.group.groupQrcode({
  frn: "opdns",
  groupId: 0,
  ope: 16420
});
  1. 保存群至通讯录
SDK.group.groupSave({
  frn: "opdns",
  groupId: 0,
  isInContacts: 0, // 是否保存在通讯录(1:是;0:否)
  ope: 16420
});
  1. 邀请好友入群
SDK.group.groupScan({
  friendId: [0], // 好友ID最少一个
  frn: "opdns",
  groupId: 0,
  ope: 16420
});
  1. 转移群主异步调用
SDK.group.groupTransfer({
  friendId: 0, // 好友ID
  frn: "opdns",
  groupId: 0,
  ope: 16420
});
  1. 获取群成员信息列表异步调用
SDK.group.groupUsers({
  frn: "opdns",
  groupId: 0,
  ope: 16420
});
  1. 开群群聊验证
SDK.group.groupVerify({
  frn: "opdns",
  groupId: 0,
  ope: 16420,
  opn: 1 // 操作(1:新增;0:移除)
});

login(登录)

SDK.login({ account: "1", password: "2" }); // 登录
SDK.logon(); // 登出

profile(资料)

  1. 设置是否自动通过联系人请求
SDK.profile.profileAutoAdd({
  allow: 1, // 是否自动通过(1:自动;0:手动)
  frn: "opdns",
  ope: 16420
});
  1. 设置是否自动通过联系人请求
SDK.profile.profileAutoJoin({
  allow: 1, // 是否自动通过(1:自动;0:手动)
  frn: "opdns",
  ope: 16420
});
  1. 设置是否自动通过联系人请求
SDK.profile.profileAvatar({
  avatar: "string", // 好友头像
  frn: "opdns",
  ope: 16420
});
  1. 修改性别
SDK.profile.profileGender({
  frn: "opdns",
  gender: 0, // 好友性别(0:未知;1:男生;2:女生)
  ope: 16420
});
  1. 获取资料
SDK.profile.profileInfo({
  frn: "opdns",
  ope: 16420
});
  1. 修改昵称,同一平台(Frn)下面的不同账户昵称不能重复
SDK.profile.profileNickname({
  frn: "opdns",
  nickname: "string", // 用户昵称
  ope: 16420
});
  1. 修改个性签名
SDK.profile.profileWhatsUp({
  frn: "opdns",
  ope: 16420,
  whatsUp: "string" // 个性签名
});

sns(关系链)

  1. 通过联系人请求
SDK.sns.snsAccept({
  act: "string", // 请求编号
  frn: "opdns",
  ope: 16420
});
  1. 添加联系人
SDK.sns.snsAdd({
  account: "string", // 微信号/手机号/二维码地址//账户
  frn: "opdns",
  helloWord: "string", // 打招呼(必填-例如:我是XXX)
  ope: 16420
});
  1. 设置联系人备注
SDK.sns.snsAutoRemark({
  friendId: 0, // 好友ID
  frn: "opdns",
  ope: 16420,
  remark: "string" // 好友备注
});
  1. 设置联系人备注
SDK.sns.snsBlacklist({
  friendId: 0,
  frn: "opdns",
  ope: 16420,
  opn: 0 // 操作(1:移除;0:设置)
});
  1. 删除联系人
SDK.sns.snsDelete({
  friendId: 0,
  frn: "opdns",
  ope: 16420
});
  1. 删除联系人
SDK.sns.snsList({
  frn: "opdns",
  ope: 16420
});

tag(标签)

  1. 标签下添加多个好友
SDK.tag.tagAdd({
  friends: [
    {
      friendId: "string" // 好友编号
    }
  ],
  frn: "opdns",
  ope: 16420,
  tagId: 0 // 标签ID
});
  1. 创建标签
SDK.tag.tagCreate({
  frn: "opdns",
  ope: 16420,
  tagName: "string" // 标签名称
});
  1. 删除标签
SDK.tag.tagDelete({
  frn: "opdns",
  ope: 16420,
  tagId: 0 // 标签ID
});
  1. 编辑标签
SDK.tag.tagEdit({
  frn: "opdns",
  ope: 16420,
  tagId: 0, //标签ID
  tagName: "string" // 标签名称
});
  1. 获取标签下好友列表 备注:获取标签下的好友。移动端创建标签完成后,通过移动端再给标签增删好友,可以通过本接口获取最新的标签下好友
SDK.tag.tagFriends({
  frn: "opdns",
  ope: 16420,
  tagId: 0
});
  1. 标签列表
SDK.tag.tagList({
  frn: "opdns",
  ope: 16420
});
  1. 移除用户好友标签
SDK.tag.tagRemove({
  friendId: 0, // 好友ID
  frn: "opdns",
  ope: 16420,
  tags: [
    {
      tagId: 0 // 标签id
    }
  ]
});
  1. 设置好友标签
SDK.tag.tagRemove({
  friendId: 0,
  frn: "opdns",
  ope: 16420,
  tags: [
    {
      base64TagName: "string", // base64编码标签名称
      tagId: 0, // 标签id
      tagName: "string" // 标签名称
    }
  ]
});

timeline(时间轴)

  1. 更换时间轴相册封面
SDK.timeline.timelineCover({
  frn: "opdns",
  img: "http://domain.com/Files/12087.jpg", // 封面图片
  ope: 16420
});
  1. 时间轴删除
SDK.timeline.timelineDelete({
  frn: "opdns",
  ope: 16420,
  timelineId: 0 // 时间轴ID
});
  1. 时间轴点赞
SDK.timeline.timelineLike({
  frn: "opdns",
  ope: 16420,
  opn: 1, // 操作(1:点赞;0:取消)
  timelineId: 0
});
  1. 时间轴信息查询 (首次获取一个好友的时间轴,latestTimeline 默认传值:0,每次能获取到最多 10 条时间轴,不够 10 条则有多少回调多少;在根据回调的时间轴 id 中,可以选取一条再次获取该条时间轴时间之前的 10 条,以此类推可以获取该好友之前的时间轴内容)
SDK.timeline.timelineList({
  friendCode: "string", // 指定人的编号(只获取他的时间轴,传机器人自己的微信编号获取自己的时间轴)
  frn: "opdns",
  latestTimelineId: 0, // 最新时间轴ID默认为0
  ope: 16420
});
  1. 设置是否允许陌生人查看十条时间轴
SDK.timeline.timelinePublic({
  allow: 1, // 是否允许(1:是;0:否)
  frn: "opdns",
  ope: 16420
});
  1. 发布时间轴
SDK.timeline.timelinePublic({
  contacts: ["string"], // 指定人的编号
  cover: "string", // 封面图片,可选
  desc: "string", // 文字的内容
  frn: "opdns",
  medias: [
    {
      id: 0, // 多媒体文件ID
      url: "string" // 多媒体文件链接
    }
  ],
  ope: 16420,
  private: 0, //可见类型(0:默认无限制;1:指定不可见;2:指定可见)
  tags: [
    {
      tagId: 0, // 标签id
      tagName: "string" // 标签名字
    }
  ],
  title: "string", // 链接的标题
  type: 1, // 时间轴类型
  url: "string" // 链接地址
});
  1. 时间轴评论
SDK.timeline.timelineReply({
  content: "string", // 评论内容
  frn: "opdns",
  ope: 16420,
  replyId: 0, // 评论id
  timelineId: 0 // 时间轴ID
});
  1. 设置允许朋友查看时间轴的范围
SDK.timeline.timelineViewable({
  frn: "opdns",
  ope: 16420,
  scope: 2 // 范围(0:3天;1;半年;2:全部)
});

更多细节请参考 IM 接口详情

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.31

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago