File Coverage

blib/lib/Weixin/Client/Private/_send_text_msg.pm
Criterion Covered Total %
statement 0 21 0.0
branch 0 10 0.0
condition 0 3 0.0
subroutine 0 3 0.0
pod n/a
total 0 37 0.0


line stmt bran cond sub pod time code
1             package Weixin::Client;
2             sub _send_text_msg {
3 0     0     my $self = shift;
4 0           my $msg = shift;
5 0           my $api = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg";
6 0           my @query_string =(
7             sid => $self->wxsid,
8             skey => uri_escape($self->skey),
9             r => $self->now(),
10             skey => uri_escape($self->skey),
11             pass_ticket => $self->pass_ticket,
12             );
13 0           my $t = $self->now();
14 0           my $post = {
15             BaseRequest => {
16             DeviceID => $self->deviceid,
17             Sid => $self->wxsid,
18             Skey => $self->skey,
19             Uin => $self->wxuin,
20             },
21             Msg => {
22             ClientMsgId => $t,
23             Content => decode("utf8",$msg->{Content}),
24             FromUserName => $msg->{FromId},
25             LocalID => $t,
26             ToUserName => $msg->{ToId},
27             Type => 1,
28             },
29             };
30 0           my $url = gen_url($api,@query_string);
31             my $callback = sub {
32 0     0     my $response = shift;
33 0           my $status = $self->_parse_send_status_data($response->content);
34 0 0 0       if(defined $status and $status->{is_success} == 0){
    0          
35 0           $self->_send_text_msg($msg);
36 0           return;
37             }
38             elsif(defined $status){
39 0 0         if(ref $msg->{cb} eq 'CODE'){
40 0           $msg->{cb}->(
41             $msg, #msg
42             $status->{is_success}, #is_success
43             $status->{status} #status
44             );
45             }
46 0 0         if(ref $self->{on_send_msg} eq 'CODE'){
47 0           $self->{on_send_msg}->(
48             $msg, #msg
49             $status->{is_success}, #is_success
50             $status->{status} #status
51             );
52             }
53             }
54 0           };
55 0           my $post_data = $self->json_encode($post);
56 0 0         print "POST $url\n$post_data\n" if $self->{debug};;
57             $self->timer2(
58             "_send_msg",
59             $self->{_send_msg_interval},
60             sub{
61 0     0     $self->asyn_http_post(
62             $url,
63             ("Content-Type"=>"application/json; charset=UTF-8"),
64             Content=>$post_data,
65             $callback,
66             );
67             },
68 0           );
69            
70             }
71             1;