package Mojo::Webqq::Util;
use Carp qw();
use Encode qw();
use IO::Handle;
use Mojo::JSON qw();
use Mojo::Util qw();
use Mojo::Webqq::Counter;
sub new_counter {
my $self = shift;
return Mojo::
from_json{
my $self = shift;
my $r = eval{
if($self->json_codec_mode == 0){
my $json = Mojo::JSON::from_json(@_);
$json;
}
elsif($self->json_cod
my $json = Mojo::JSON::decode_json(@_);
$self->reform($json);
$json;
}
else{
my $json = Mojo::JSON::from_json(@_);
$json;
ile::Spec->catfile($ENV{MOJO_WEBQQ_TMPDIR},join('','mojo_webqq_state_',$ENV{MOJO_WEBQQ_ACCOUNT},'.json')) if not defined $ENV{MOJO_WEBQQ_STATE_PATH};
$ENV{MOJO_WEBQQ_QRCODE_PATH} = File::Spec->cat
e Mojo::JSON ();
use Mojo::Util ();
use base qw(Mojolicious::Controller);
sub render{
my $self = shift;
if($_[0] eq 'json'){
$self->res->headers->content_type('application/json');
$self->SUPER::render(data=>Mojo::JSON::to_json($_[1]),@_[2..$#_]);
}
else{$self->SUPER::render(@_)}
}
sub safe_render{
my $self = shift;
$self->render(@_) if (defined $self->tx and
tle or !$message;
my $result=$client->http_post($api_url, {json=>1},
form=>{
nsp_fmt => JSON,
deviceToken => $deviceToken,
push_t
message=>$client->to_json({isAt=>$isAt,type=>$type,title=>$title,message=>$message,msgId=>$msgId,senderType=>$senderType}),
},
sub{
my $json = shift;
if(not defined $json){
$client->debug("[".__PACKAGE__."]华为消息推送失败: 返回结果异常");
return;
}
else{
ge;
$client->http_post($api_url,
{'Authorization'=>"key=$api_key",json=>1},
json=>{
registration_ids=> $registration_ids,
$collapse_key
"message_id":"0:1484103730761325%9b9e6c13f9fd7ecd"}]}"
my $json = shift;
if(not defined $json){
$client->debug("[".__PACKAGE__."]GCM消息推送失
$client->debug("[".__PACKAGE__."]GCM消息推送完成:$json->{multicast_id}/$json->{success}/$json->{failure}");
}
}
);
});
$client
nt;
$client->http_post($api_url,
{'Authorization'=>"key=$api_key",json=>1},
json=>{
registration_ids=> $registration_ids,
$collapse_key
"message_id":"0:1484103730761325%9b9e6c13f9fd7ecd"}]}"
my $json = shift;
if(not defined $json){
$client->debug("[".__PACKAGE__."]GCM消息推送失
$client->debug("[".__PACKAGE__."]GCM消息推送完成:$json->{multicast_id}/$json->{success}/$json->{failure}");
}
}
);
});
$client
$msg->allow_plugin(0);
my $salt = time;
$client->http_get($api,{json=>1},form=>{
q => $query,
from => 'auto',
to
b{
my $json = shift;
if( not defined $json ){$msg->reply("翻译失败: api接口不可用")}
elsif(defined $json and exists $json->{error_code}){
可用(" . $json->{error_code} . " " . $json->{error_msg} . ")");
}
elsif(defined $json){
$msg->reply( join " ",map {$_->{dst}} @{ $json->{trans_re
json => 1,
};
#使用http_get从API获取所需信息
$client->http_get($API.$prov,$headers,sub{
my $json = shift;
return unless defined $json;
my $resultArray = $json
is_transparent eq 1) {
$client->http_post($api_url,
{'Authorization'=>"key=$api_key",
json=>1
},
form=>{
pass_through => 1,
registration_id => $regi
t->to_json({isAt=>$isAt,type=>$type,title=>$title,message=>$message,msgId=>$msgId,senderType=>$senderType}),
},
sub{
my $json = shift;
if(not defined $json){
米消息推送状态:$json->{error}");
}
}
);
} else {
$client->http_post($api_url,
{'Authorization'=>"key=$api_key",
json=>1
},
form=>{
roxy.html?v=20130916001&callback=1&id=1',
json => 1,
ua_request_timeout => 10,
ua_retry_times => 3,
};
my $json = $self->http_get($self->gen_url($api_url,@query
return undef unless defined $json;
if($json->{retcode}!=0){
$self->error("获取数据验证参数失败...");
return 0;
}
$self->vfwebqq($json->{result}{vfwebqq});
ret
k = sub {
my ($json,$ua,$tx) = @_;
eval{
#分析接收到的消息,并把分析后的消息放到接收消息队列中
if(defined $json){
$sel
f->parse_receive_msg($json);
$self->emit(receive_raw_message=>$tx->res->body,$json);
}
};
$self->error($@) if $@;
$self->is_polling(0);
#重
m/proxy.html?v=20151105001&callback=1&id=2",json=>1};
my $id = $self->http_post(
$api_url,
$headers,
form=>{r=>$self->to_json(\%r)},
$callback
);
$self->
d_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->receiver_id,
face => $self->user->face || 570,
content => $self->to_json($content),
msg_id => $msg->id,
clientid => $self->clientid,
psessionid
rs = {
Referer=>'https://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1',
json=>1,
ua_request_timeout => $self->model_update_timeout,
ua_retry_times => 3,
}
?0:1;
my $handle = sub{
my $json = shift;
my $friends_state = shift;
return undef unless defined $json;
return undef if $json->{retcode}!=0 ;
my %categories
$state{$_->{uin}}{client_type} = $_->{client_type};
}
}
for(@{ $json->{result}{categories}}){
$categories{ $_->{'index'} } = {'sort'=>$_->{'sort'},name=>$
my $json = $self->http_post($api,{Referer=>"http://qun.qq.com/member.html",json=>1},form=>{gc=>$uid,ul=>join("|",@qq),flag=>0,bkn=>$self->get_csrf_token});
return if not defined $json;
re
turn if $json->{ec}!=0;
return 1;
}
1;
= {
Referer => 'https://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1',
json=>1,
ua_request_timeout => $self->model_update_timeout,
ua_retry_times => 3,
}
dle = sub{
my $json = shift;
return undef unless defined $json;
return undef unless exists $json->{result}{gnamelist};
my $group_list_info = $json->{result}{gnamelist};
$self->to_json(\%r)},) );
}
else{
$self->http_get($api_url,$headers,form=>{r=>$self->to_json(\%r)},sub{
my $json = shift;
$callback->( $handle->($json) );
= {
Referer => 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2',
json => 1,
};
my %r = (
vfwebqq => $self->vfwebqq,
clientid
allback eq "CODE"?0:1;
my $handle = sub{
my $json = shift;
return undef unless defined $json;
return undef if $json->{retcode}!=0 ;
my %type = (0 => 'friend',1 => '
group', 2 => 'discuss');
my @recent;
for(@{$json->{result}}){
next unless exists $type{$_->{type}};
$_->{type} = $type{$_->{type}};
if($_->{type} eq
callback=1&id=1',json=>1};
my @query_string = (
tuin => $uin,
vfwebqq => $self->vfwebqq,
t => time,
);
my $json = $self->http_g
return undef unless defined $json;
return undef if $json->{retcode} !=0;
#{"retcode":0,"result":[{"uin":308165330,"lnick":""}]}
my $single_long_nick = $json->{result}[0]{lnick};
retu
nfo/set_group_shutup";
my $json = $self->http_post($api,{Referer=>"http://qinfo.clt.qq.com/qinfo_v3/member.html",json=>1},form=>{gc=>$uid,shutup_list=>$self->to_json([map {{uin=>$_,t=>$t}} @qq]),b
kn=>$self->get_csrf_token});
return if not defined $json;
return if $json->{ec}!=0;
return 1;
}
1;
qinfo.clt.qq.com/cgi-bin/qun_info/set_group_admin";
my $json = $self->http_post($api,{Referer=>"http://qinfo.clt.qq.com/member.html",json=>1},
form=>{src=>"qinfo_v2",gc=>$uid,u=>join("
|",$qq[0]),op=>0,bkn=>$self->get_csrf_token});
return if not defined $json;
return if $json->{ec}!=0;
return 1;
}
1;
g,
);
return;
}
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}}
e
s_sig ,
face => $self->user->face || 591,
content => $self->to_json($content),
msg_id => $msg->id,
service_type => $msg->via eq "group"?0
.qq.com/channel/send_discu_msg2';
my $callback = sub{
my $json = shift;
$msg->parse_send_status_msg( $json );
if(!$msg->is_success and $msg->code != -3 and $msg->ttl >
= {
Referer => 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2',
json => 1,
};
my @content = map {
if($_->{type} eq "txt"){$_->{content}}
sg->discuss_id,
face => $self->user->face || 591,
content => $self->to_json($content),
msg_id => $msg->id,
clientid => $self->clientid,
psess