File Coverage

blib/lib/Mojo/Weixin/Message/Remote/_send_text_message.pm
Criterion Covered Total %
statement 0 20 0.0
branch 0 8 0.0
condition 0 3 0.0
subroutine 0 2 0.0
pod n/a
total 0 33 0.0


line stmt bran cond sub pod time code
1             sub Mojo::Weixin::_send_text_message {
2 0     0     my $self = shift;
3 0           my $msg = shift;
4 0           my $api = "https://".$self->domain . "/cgi-bin/mmwebwx-bin/webwxsendmsg";
5 0           my @query_string =();
6 0 0         push @query_string,(pass_ticket => $self->url_escape($self->pass_ticket)) if $self->pass_ticket;
7 0 0         my $post = {
8             BaseRequest => {
9             DeviceID => $self->deviceid,
10             Sid => $self->wxsid,
11             Skey => $self->skey,
12             Uin => $self->wxuin,
13             },
14             Msg => {
15             ClientMsgId => $msg->uid,
16             Content => $msg->content,
17             FromUserName => $msg->sender_id,
18             LocalID => $msg->uid,
19             ToUserName => ($msg->type eq "group_message"?$msg->group_id:$msg->receiver_id),
20             Type => 1,
21             },
22             };
23             my $callback = sub {
24 0     0     my $json = shift;
25 0           $msg->_parse_send_status_data($json);
26 0 0 0       if(!$msg->is_success and $msg->ttl > 0){
27 0           $self->debug("消息[ " . $msg->id . " ]发送失败,尝试重新发送,当前TTL: " . $msg->ttl);
28 0           $self->message_queue->put($msg);
29 0           return;
30             }
31             else{
32 0 0         if(ref $msg->cb eq 'CODE'){
33 0           $msg->cb->(
34             $self,
35             $msg,
36             );
37             }
38              
39 0           $self->emit(send_message => $msg);
40             }
41 0           };
42             #Mojo::JSON::to_json will escape the slash charactor '/' into '\/'
43             #Weixin Server doesn't supported this feature
44             #So we do some dirty work there to disable this feature
45 0           $post->{Msg}{Content} =~ s#/#__SLASH__#g;
46 0           my $json = $self->to_json($post);
47 0           $json =~ s#__SLASH__#/#g;
48             # dirty work done
49              
50 0           $self->http_post($self->gen_url($api,@query_string),{json=>1,'Content-Type'=>'application/json'},$json,$callback);
51             }
52             1;