方法:
dump #打印消息结构,主要用于调试
to_json_hash #将消息转换为json兼容的hash,方便和外部系统交互
#常见的接收
获取发送者的名称
my $json_hash = $msg->to_json_hash(); #获取到hash引用
my $json_text = $client->to_json($json_hash); #将hash转换为json字符串
$msg->dump();
$ms
#json=>1 表示将响应的json数据进行转换得到perl的hash引用
#retry_times=>3 表示请求失败自动重试次数,默认使用$client->ua_retry_times的值
my $json_decode_h
p_message{
my($self,$msg) = @_;
my $callback = sub{
my $json = shift;
$msg->parse_send_status_msg( $json );
if( !$msg->is_success and $msg->ttl > 0){
$self-
= {
Referer => 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2',
json => 1,
};
my @content = map {
if($_->{type} eq "txt"){$_->{content}}
$msg->group_id,
face => $self->user->face || 591,
content => $self->to_json($content),
msg_id => $msg->id,
clientid => $self->clientid,
psess
ost_json = {};
$post_json->{post_type} = "event";
$post_json->{event} = $event;
$post_json->{params} = [@args];
$client->stdout_line($client->to_json($p
ost_json)) if $data->{post_stdout};
if(defined $data->{post_api}){
my($data,$ua,$tx) = $client->http_post($data->{post_api},{ua_connect_timeout=>5,ua_request_timeout=>5,ua_
inactivity_timeout=>5,ua_retry_times=>1},json=>$post_json);
if($tx->res->is_success){
$client->debug("插件[".__PACKAGE__ ."]事件[".$event . "](@args)上报成
$url,{json => 1,Referer => "https://glot.io/run/$language?version=latest"},json=>\%r,sub{
my $json = shift;
return unless defined $json;
if ($json->{std
:---->\n".$json->{stdout});
}else{
$client->reply_message($msg,"执行<$language>出错:---->\n".$json->{stdout}."--->".$json->{error}."--->".$json->{stderr});
e,{json=>1},sub{
my $json = shift;
return unless defined $json;
my $doc;
my $code;
if(defined $json->{code} and $json->{
code} == 404){
$doc = "模块名称: $module ($json->{message})" ;
$code = 404;
$metacpan_cache->store($module,{code=>$code,doc=>$doc},6048
= 200;
my $author = $json->{author};
my $version = $json->{version};
my $abstract= $json->{abstract};
my $podlin
my $delay =shift;
$client->http_get('http://apis.baidu.com/gushi/grid/p1',{json=>1,apikey=>$data->{apikey}||'20d7db97e337ffa35ae0838439c9db5d'},form=>{count=>1,fmt=>0},$delay->b
my $json = shift;
return if not defined $json;
return if $json->{status} != 0;
my $id = $json->{data}[0]{id} if ref $json->{data} eq
p2',{json=>1,apikey=>$data->{apikey}||'20d7db97e337ffa35ae0838439c9db5d'},form=>{id=>$id,fmt=>0},sub{
my $json = shift;
return if not defined $json;
$senderType = '2';
}
return if !$title or !$message;
my $messageJson = '{"content":"{\"isAt\":\"'.$isAt.'\",\"type\":\"'.$type.'\",\"title\":\"'.$title.'\",\"message\
}"}';
print "appId=".$app_id."messageJson=".$messageJson."pushIds=".$registration_id.$api_key;
my $sign = md5_sum("appId=".$app_id."messageJson=".$messageJson."pushIds=".$registration_id.$api_key)
=>1,ua_debug_res_body=>1,json=>1},
form=>{
appId => $app_id,
pushIds => $registration_id,
messageJson=>$messageJson,
sign => $sign,
g/bot' . $data->{api_key} .'/sendPhoto';
my $response = $client->http_post($telegram_api,{json=>1},form=>{
chat_id => $data->{chat_id},
caption => 'QQ帐号' .(defined
data->{api_key};
my $response = $client->http_post($telegram_api . '/editMessageCaption',{json=>1},form=>{
chat_id => $data->{chat_id},
message_id => $last_id,
ssage_id (@qrcode_message_ids) {
$client->http_post($telegram_api . '/deleteMessage',{json=>1},form=>{
chat_id => $data->{chat_id},
message_id => $message_i
alar::Util qw(blessed);
use Data::Dumper;
sub client {
return $Mojo::Webqq::_CLIENT;
}
sub to_json_hash{
my $self = shift;
my $hash = {};
for(keys %$self){
next if substr($_
eq "ARRAY"){
for my $m(@{$self->{member}}){
my $member_hash = $m->to_json_hash();
push @{$hash->{member}},$member_hash;
}
}
}
$json = {
"key" => $data->{apikey} || "f771372ffd054183bfcdf260d7c7ad5a",
"userid" => $msg->sender->id,
"info" => $input,
};
$json
pi,{json=>1},json=>$json,sub{
my $json = shift;
return unless defined $json;
return if $json->{code}=~/^4000[1-7]$/;
my $reply;
if($json->{c
return unless $json->{text};
$reply = $json->{text};
}
elsif($json->{code} == 200000){
$reply = "$json->{text}$json->{url}";
= {
Referer => 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2',
json => 1,
};
my @query_string = (
newstatus => $mode,
clientid
=> time,
);
my $json = $self->http_get($self->gen_url($api_url,@query_string),$headers);
return undef unless defined $json;
return undef if $json->{retcode} !=0;
$self->mod
Referer => 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2',
json => 1,
};
my %r = (
status => $self->mode,
ptwebqq => $s
lf->passwd_sig;
#}
my $data = $self->http_post($api_url,$headers,form=>{r=>$self->to_json(\%r)});
return 0 unless defined $data;
if($data->{retcode} ==0){
if(defined $self
/;
}
sub to_json_hash{
my $self = shift;
my $json = {};
for my $key (keys %$self){
next if substr($key,0,1) eq "_";
if($key eq "sender"){
$json->{sender} = $
ame;
$json->{sender_uid} = $self->sender->uid;
}
elsif($key eq "receiver"){
$json->{receiver} = $self->receiver->displayname;
$json->{receiver_uid}
group"){
$json->{group} = $self->group->displayname;
$json->{group_uid} = $self->group->uid;
}
elsif($key eq "discuss"){
$json->{discuss} = $self->d
t;
my $json = shift;
return if $self->is_stop;
return unless defined $json;
if ( $json->{retcode} == 0 ) {
$self->poll_failure_count(0);
for my $m ( @{ $json->{result}
#更新客户端ptwebqq值
elsif ( $json->{retcode} == 116 ) {
$self->debug("更新ptwebqq的值[ $json->{p} ]");
$self->ptwebqq($json->{p});
$self->ua->cookie_jar->ad
:Response->new(name=>"ptwebqq",value=>$json->{p},path=>"/",domain=>"qq.com",),
);
}
#未重新登录
elsif ( $json->{retcode} == 100 or $json->{retcode} == 103) {
$self->w
的云存储路径,防止好像干扰
my $json = $client->http_post('https://sm.ms/api/upload',{json=>1},form=>{
format=>'json',
smfile=>{filename=>$qrcode_path,conte
if(not defined $json){
$client->warn("二维码图片上传云存储失败: 响应数据异常");
return;
}
elsif(defined $json and $json->{code} ne 'succes
存储失败: " . $json->{msg});
return;
}
$client->qrcode_upload_url($json->{data}{url});
$client->info("二维码已上传云存储[ ". $json->{data}{url} . " ]")
de($signtemp . $orignal,"");
my $json = $client->http_post("http://web.file.myqcloud.com/files/v1/$appid/$bucket/$name",
{ Authorization=>$sign, json=>1 ,ua_debug_req_body=>0},
fo
);
if(not defined $json){
$client->warn("二维码图片上传云存储失败: 响应数据异常");
return;
}
elsif(defined $json and $json->{code} != 0 ){
$c
lient->warn("二维码图片上传云存储失败: " . $json->{message});
return;
}
my $url = $json->{data}{source_url};
$url=~s/(^https?:\/\/)([^\/]+)(.*)/$1$mydomain$3/ if (
n2';
my $headers = {Referer=>'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2',json=>1};
my %r = (
status => $self->mode,
key => "",
ptweb
psessionid,
);
my $data = $self->http_post($api_url,$headers,form=>{r=>$self->to_json(\%r)});
unless(defined $data){
$self->relogin();
return 0;
}
if($data
}
}
sub _http_request{
my $self = shift;
my $method = shift;
my %opt = (
json => 0,
blocking => 0,
ua_retry_times => $self-
dy
);
if(ref $_[1] eq "HASH"){#with header or option
$opt{json} = delete $_[1]->{json} if defined $_[1]->{json};
$opt{blocking} = delete $_[1]->{blocking} if defined $_[1]->{bl
ie();
if(defined $tx and $tx->res->is_success){
my $r = $opt{json}?$self->from_json($tx->res->body):$tx->res->body;
$cb->($r,$ua,$tx);
}
$json = {plugin => []};
for my $attr (@attr){
$json->{$attr} = $self->$attr;
}
$json->{previous_state} = $previous_state;
$json->{pid} = $$;
$json-
>{os} = $^O;
for my $p (keys %{ $self->plugins }){
push @{ $json->{plugin} } , { name=>$self->plugins->{$p}{name},priority=>$self->plugins->{$p}{priority},auto_call=>$self->plugin
,call_on_load=>$self->plugins->{$p}{call_on_load} } ;
}
$self->spurt($self->to_json($json),$self->state_path);
};
$self->warn("客户端状态信息保存失败:$@") if $@;
}
自其他设备的消息,体验会更好一些
has json_codec_mode => 0; #0表示使用from_json/to_json 1表示使用decode_json/encode_json
has default_send_real_comp_sign => 0; #设为真
sub {File::Spec->catfile($_[0]->tmpdir,join('','mojo_webqq_state_',$_[0]->account || 'default','.json'))};
has ioloop => sub {Mojo::IOLoop->singleton};
has keep_cookie => 1;
has
ator->(@_);
});
$transactor->add_generator(json=>sub{
$_[1]->req->body($self->to_json($_[2]))->headers->content_type('application/json');
return $_[1];
});
Mojo::UserAg