Method: WeChat::Bot::Client#send_text

Defined in:
lib/wechat/bot/client.rb

#send_text(username, text) ⇒ Hash<Object,Object>

发送消息

Parameters:

  • 目标UserName

  • 消息内容

Returns:

  • 发送结果状态



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/wechat/bot/client.rb', line 354

def send_text(username, text)
  url = api_url('webwxsendmsg')
  params = params_base_request.merge({
    "Scene" => 0,
    "Msg" => {
      "Type" => 1,
      "FromUserName" => @bot.profile.username,
      "ToUserName" => username,
      "Content" => text,
      "LocalID" => timestamp,
      "ClientMsgId" => timestamp,
    },
  })

  r = @session.post(url, json: params)
  r.parse(:json)
end