IM常用消息体&文本消息&自定义消息

消息对象

webim.Msg(
    sess, isSend, seq, random,time,fromAccount,subType,fromAccountNick
)

消息元素对象 Msg.Elem

webim.Msg.Elem(type,content)

消息元素对象(文本)

webim.Msg.Elem.Text(text)

消息元素对象(自定义)

webim.Msg.Elem.Custom(data,desc,ext)

自定义消息webim.Msg.Elem.Custom(data,desc,ext)项目使用

  • data: 前端展示用的相关字段
  • desc: 后台处理使用的相关字段
  • ext: 拓展(如事件号等等)
  • 发送聊天消息

消息对象类型: 1 文本 2 商品(旧)3 普通商品 4 团购 5 砍价 6 个人微信二维码 7 群微信二维码 20 图片

/**
聊天页面列表通用字段
**/
let msg = {
          from_account_id: this.imInfo.im_account, // 接收方im账号
          avatar: this.userInfo.avatar, // 发送方头像
          content: value, // 本文内容
          time: timeStamp, // 聊天当前时间
          msgTimeStamp: timeStamp, // 聊天当前时间
          nickName: this.userInfo.nickName, // 发送方昵称
          sessionId: this.userInfo.account, // 发送发IM账号
          unreadMsgCount: 0, // 未读聊天数量
          type: 1, // 消息对象类型log_type
/** (图文并茂才有)例如:商品/活动  **/
          url: msgUrl, // 图片url
          title: msgTitle, // 标题
          goods_price: this.selectGoods.goods_price, // 商品价格
          original_price: this.selectGoods.original_price, // 商品原价
          shop_name: this.selectGoods.shop_name, // 店铺名称
        }
/**
消息列表页面通用字段
**/
let addMsg = {
          text: value, // 文本内容同content
          time: timeStamp, // 聊天当前时间
          msgTimeStamp: timeStamp, // 聊天当前时间
          fromAccount: this.id, // 接收方im账号
          sessionId: this.id, // 接收方im账号
          unreadMsgCount: 0, // 未读数量
          avatar: this.currentMsg.avatar, // 接收方头像
          nickName: this.currentMsg.nickName // 接收方昵称
        }
/**
 图片20
**/
let data = {
  image_id: resData.id, // 图片id
  url: resData.url // 图片路径
}
let desc = {log_type: 20}
let ext = '20005'
/**
 * 商品3/活动(团购4,砍价5)
 * @type {{}}
 */
let data = {
  url: this.selectGoods.image_url, // 图片url
  goods_id: this.selectGoods.id, // 商品&活动id
  title: this.selectGoods.title, // 标题
  goods_price: this.selectGoods.goods_price, // 价格
  original_price: this.selectGoods.original_price, // 原价 
  avatar: this.userInfo.avatar, // 发送方头像
  shop_name: this.selectGoods.shop_name // 店铺名称
}
let desc = {log_type: logType} // 3 4 5
let ext = '20005'
/**
 * 个人6/群7 微信二维码
 * @type {{}}
 */
let data = {}
let desc = {log_type: ? } // 6 7
let ext = '20005'
  • 发送行为消息
// event_no: 20005特殊事件
const DEFAULTOBJ = {
  event_no: 0, // 事件号
  log_type: 0, // 消息对象类型
  goods_id: 0, // 商品id
  activity_id: 0, // 活动id
  flow_id: 0, // 绑定关系的来源id
  store_id: 0, // 线下门店id
  merchant_id: 0, // 商家id
  shop_id: 0, // 线上店铺id
  customer_id: 0, // 顾客id
  total: '', // 金额,总金额(不细化)
  title: '', // 标题(不细化)
  customer_name: '' // 顾客名称
}

注意事项:

小程序运行时环境的差异,目前IMSDK的部分接口在小程序尚未支持图片和文件上传
小程序rich-text组件渲染部分base64图片存在渲染不完整的情况

你可能感兴趣的:(IM常用消息体&文本消息&自定义消息)