Class: OPQ::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/opqr/api.rb

Instance Method Summary collapse

Instance Method Details

#send_text_group(to_group, content, form_qq) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/opqr/api.rb', line 31

def send_text_group(to_group, content, form_qq)
  url = URI("http://"+$api_url.to_s+":"+$http_port.to_s+"/v1/LuaApiCaller?funcname=MagicCgiCmd&timeout=10&qq="+form_qq.to_s)
  http = Net::HTTP.new(url.host, url.port)
  request = Net::HTTP::Post.new(url)
  request["User-Agent"] = "Apifox/1.0.0 (https://www.apifox.cn)"
  request["Content-Type"] = "application/json"
  request.body = {
    "CgiCmd": "MessageSvc.PbSendMsg",
    "CgiRequest": {
      "ToUin": to_group.to_i,
      "ToType": 2,
      "Content": content.to_s,
      "AtUinLists": [
        {
          "QQNick": "0.0",
          "QQUid": 941094692
        }
      ]
    }
  }.to_json
  response = http.request(request)
  t = JSON.parse(response.read_body)
  if t['CgiBaseResponse']['ErrMsg'].empty?
    puts "[文字发群] " +form_qq.to_s+"->"+to_group.to_s+" 成功"
  else
    puts "[文字发群] " +form_qq.to_s+"->"+to_group.to_s+" " + t['CgiBaseResponse']['ErrMsg']
  end
end

#send_text_qq(to_qq, content, form_qq) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/opqr/api.rb', line 7

def send_text_qq(to_qq, content, form_qq)
  url = URI("http://"+$api_url.to_s+":"+$http_port.to_s+"/v1/LuaApiCaller?funcname=MagicCgiCmd&timeout=10&qq="+form_qq.to_s)
  http = Net::HTTP.new(url.host, url.port)
  request = Net::HTTP::Post.new(url)
  request["User-Agent"] = "Apifox/1.0.0 (https://www.apifox.cn)"
  request["Content-Type"] = "application/json"
  request.body = {
    "CgiCmd": "MessageSvc.PbSendMsg",
    "CgiRequest": {
      "ToUin": to_qq.to_i,
      "ToType": 1,
      "Content": content.to_s
    }
  }.to_json
  response = http.request(request)
  t = JSON.parse(response.read_body)
  # 发Q不显示失败

  if t['CgiBaseResponse']['ErrMsg'].empty?
    puts "[文字发Q] " +form_qq.to_s+"->"+to_qq.to_s+" 成功"
  else
    puts "[文字发Q] " +form_qq.to_s+"->"+to_qq.to_s+" " + t['CgiBaseResponse']['ErrMsg']
  end
end