生一个监听本地指定端口的HTTP服务器,用于接收api请求
返回数据完全为JSON格式,接口包括:
获取个人信息 /openqq/get_user_info
获取好友信息
int "Report data...\n" if $self->{verbose} or $self->{debug};
my $res = $ua->post($url => json => $data)->res;
print "Done.\n" if $self->{verbose} or $self->{debug};
die "benc
use JSON;
sub Webqq::Client::_get_recent_info {
my $self = shift;
my $ua = $self->{ua};
return undef if $self->{type} ne 'smartqq';
my $api_url = 'http://d.web2.qq.com/channel/get_re
a->post($api_url,[r=>JSON->new->utf8->encode(\%r)],@headers);
if($response->is_success){
print $response->content(),"\n" if $self->{debug};
my $json = JSON->new->utf8->decode($
());
return undef if $json->{retcode}!=0 ;
my %type = (0 => 'friend',1 => 'group', 2 => 'discuss');
my @recent;
for(@{$json->{result}}){
next unless
use JSON;
use Encode;
sub Webqq::Client::get_single_long_nick{
my $self = shift;
my $uin = shift;
my $cache_data = $self->{cache_for_single_long_nick}->retrieve($uin);
return
response->content(),"\n" if $self->{debug};
my $json = JSON->new->utf8->decode( $response->content() );
return undef if $json->{retcode} !=0;
#{"retcode":0,"result":[{"uin"
:308165330,"lnick":""}]}
my $single_long_nick = encode("utf8",$json->{result}[0]{lnick});
$self->{cache_for_single_long_nick}->store($uin,$single_long_nick);
return $single_lon
qw(confess cluck);
use Tk;
use Tk::Photo;
use Tk::PNG;
use Tk::JPEG;
use Data::Dumper;
use JSON;
use Try::Tiny;
## Version string
our $VERSION = qq{0.05};
## Used when importing a form,
($param)
=over 2
=item B<Description>
initialize the form from a HASH reference, JSON string, or JSON file.
In all cases, the hash should have the following format
{
title =>
ng',
},
]
}
=item B<Parameters>
$param - HASH reference, or scalar containin JSON string, or filename
=item B<Return>
NONE
=back
=cut
##----------------------------
use JSON;
use Webqq::Client::Util qw(hash);
sub Webqq::Client::_get_user_friends{
my $self = shift;
my $api_url = 'http://s.web2.qq.com/api/get_user_friends2';
my $ua = $self->{ua};
my
$ua->post($api_url,[r=>JSON->new->utf8->encode(\%r)],@headers);
if($response->is_success){
print $response->content(),"\n" if $self->{debug};
my $json = JSON->new->utf8->decode($re
sponse->content());
return undef if $json->{retcode}!=0 ;
my $friends_state = $self->_get_friends_state();
my %categories ;
my %info;
my %marknames;
my
heckbox;
use Tk::FormUI::Field::Combobox;
use Tk::FormUI::Field::Directory;
use Data::Dumper;
use JSON;
use Try::Tiny;
## Version string
our $VERSION = qq{1.07};
Readonly::Scalar our $READONLY =>
ialize($param)
=over 2
=item B<Description>
initialize the form from a HASH reference, JSON string, or JSON file.
In all cases, the hash should have the following format
{
title => 'My Form
,
],
}
]
}
=item B<Parameters>
$param - HASH reference, or scalar containin JSON string, or filename
=item B<Return>
NONE
=back
=cut
##--------------------------------------
use JSON;
use Webqq::Client::Util qw(code2state code2client);
sub Webqq::Client::_get_friends_state {
my $self = shift;
return undef if $self->{type} ne 'smartqq';
my $ua = $self->{ua};
),"\n" if $self->{debug};
my $json = JSON->new->utf8->decode( $response->content() );
return undef if $json->{retcode} !=0;
for(@{$json->{result}}){
$_->{client
_type} = code2client($_->{client_type});
$_->{state} = $_->{status};
delete $_->{status};
}
return $json->{result};
}
else{return undef}
}
1;
the truly REST. Catalyst::Controller::REST and
CatalystX::Eta::Controller::REST only implement a JSON/YAML response, but lot of people would call those applications REST.
Please do not use XML respo
alystX::Eta::Controller::TypesValidation;
use Moose::Role;
use Moose::Util::TypeConstraints;
use JSON::MaybeXS;
sub validate_request_params {
my $self = shift;
my ( $c, %fields ) = @_;
se JSON::MaybeXS;
BEGIN { extends 'Catalyst::Controller::REST' }
__PACKAGE__->config(
default => 'application/json',
'map' => {
'application/json' => 'JSON',
'text/x-json'
=> 'JSON',
},
);
sub end : Private {
my ( $self, $c ) = @_;
#... do things before Serializing ...
my $code = $c->res->status;
if ( scalar( @{ $c->error } ) ) {
$code
0;
use strict;
use warnings;
our $VERSION = '0.001001';
use Carp qw/croak/;
use HTTP::Tiny;
use JSON::MaybeXS;
use Scalar::Util qw/blessed/;
my $ht = HTTP::Tiny->new(
agent => "WebService-Sca
s->{headers}{'X-Auth-Token'} = $$self if $$self;
$opts->{headers}{'Content-Type'} = 'application/json';
my $ret = $ht->request($method, $url, $opts);
die 'Request to Scaleway API server was unsucce
. $ret->{status} . ' ' . $ret->{reason} . '; ' . $ret->{content} unless $ret->{success};
decode_json $ret->{content} if $ret->{status} != 204;
}
sub _get { shift->_request(GET => @_) }
sub _p
Mojo::Base 'Mojo::UserAgent';
use Mojo::Parameters;
use Mojo::URL;
use Mojo::UserAgent;
use Mojo::JSON 'j';
use Mojo::Util 'slurp';
use Mojo::Collection 'c';
use Mojo::Cloudstack::Base;
use Mojo::Clou
LOAD;
chomp(our $user = `whoami`);
our $cf = File::HomeDir->users_home($user) . "/.cloudmojo/api.json";
sub _build_request {
my ($self, $params) = @_;
my $baseurl = sprintf ("%s://%s:%s%s?", $se
, $self->port, $self->path);
$params->{ apiKey } = $self->api_key;
$params->{ response } = 'json';
my $secret_key = $self->secret_key;
my $req_params = Mojo::Parameters->new();
foreach my
use JSON;
sub Webqq::Client::_get_group_sig {
my $self = shift;
my($id,$to_uin,$service_type,) = @_;
my $cache_data = $self->{cache_for_group_sig}->retrieve("$id|$to_uin|$service_type");
nt() if $self->{debug};
my $json = JSON->new->utf8->decode($response->content());
return undef if $json->{retcode}!=0;
return undef if $json->{result}{value} eq "";
$s
elf->{cache_for_group_sig}->store("$id|$to_uin|$service_type",$json->{result}{value},300);
return $json->{result}{value} ;
}
else{return undef}
}
1;
use JSON;
use Webqq::Client::Util qw(code2state);
sub Webqq::Client::_get_friend_info{
my $self = shift;
my $uin = shift;
my $api_url = 'http://s.web2.qq.com/api/get_friend_info2';
my
" if $self->{debug};
my $json = JSON->new->utf8->decode( $response->content() );
return undef if $json->{retcode} !=0;
my $user_info = $json->{result};
for my $key
use JSON;
use Webqq::Client::Util qw(console);
sub Webqq::Client::get_qq_from_uin{
my $self = shift;
my $uin = shift;
my $cache_data = $self->{cache_for_uin_to_qq}->retrieve($uin);
re
print $response->content(),"\n" if $self->{debug};
my $json = JSON->new->utf8->decode( $response->content() );
if($json->{retcode} !=0){
console "从指定uin: $uin 查询
$self->{cache_for_uin_to_qq}->store($uin,$json->{result}{account});
$self->{cache_for_qq_to_uin}->store($json->{result}{account},$uin);
return $json->{result}{account};
}
}
1;
use JSON;
use Webqq::Client::Util qw(console);
sub Webqq::Client::_relink{
my $self = shift;
$self->{login_state} = 'relink';
console "正在进行重新连接...\n";
my $ua = $self->{
for(my $i=0;$i<=$self->{ua_retry_times};$i++){
my $response = $ua->post($api_url,[r=>JSON->new->utf8->encode(\%r)], @headers);
if($response->is_success){
print $respon
ntent() if $self->{debug};
my $content = $response->content();
my $data = JSON->new->utf8->decode($content);
if($data->{retcode} ==0){
$self->{qq_pa
use JSON;
sub Webqq::Client::_recv_message{
my $self = shift;
return if $self->{is_stop};
my $ua = $self->{asyn_ua};
my $api_url = ($self->{qq_param}{is_https}?'https':'http') . '://d.
$r{key} = 0;
$r{ids} = [];
}
my $post_content = [
r => JSON->new->utf8->encode(\%r),
];
if($self->{type} eq 'webqq'){
push @$post_content,(
use JSON;
use Webqq::Client::Util qw(console);
sub Webqq::Client::get_dwz {
my $self = shift;
my $url = shift;
my $api = 'http://dwz.cn/create.php';
my $ua = $self->{ua};
my $res;
alarm 0;
if($res->is_success){
my $json = JSON->new->utf8->decode($res->content);
$dwz = $json->{tinyurl} if $json->{status}==0;
};
};
console "[Webqq:
use JSON;
sub Webqq::Client::_get_group_list_info{
my $self = shift;
my $ua = $self->{ua};
my $api_url = 'http://s.web2.qq.com/api/get_group_name_list_mask2';
my @headers = $self->{ty
webqq => $self->{qq_param}{vfwebqq},
);
my $post_content = [
r => JSON->new->encode(\%r),
];
#if($self->{debug}){
# require URI;
# my $uri = URI
f $self->{debug};
my $json = JSON->new->utf8->decode( $response->content() );
return undef unless exists $json->{result}{gnamelist};
return $json->{result};
}
else{ret