Method: WeChat::Bot::Client#send_text

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

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

发送消息

Parameters:

  • username (String)

    目标UserName

  • text (String)

    消息内容

Returns:

  • (Hash<Object,Object>)

    发送结果状态



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

def send_text(username, text)
  url = "#{store(:index_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