| 1 | 0 | ▶ | sub Mojo::Weixin::_send_text_message { | ||||||||||||||||||||||||||
|
Subroutine
_send_text_message: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 2 | 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 | ▶ | push @query_string,(pass_ticket => $self->url_escape($self->pass_ticket)) if $self->pass_ticket; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 7 | 0 | ▶ | my $post = { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | my $callback = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 24 | 0 | my $json = shift; | |||||||||||||||||||||||||||
| 25 | 0 | $msg->_parse_send_status_data($json); | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | if(!$msg->is_success and $msg->ttl > 0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $msg->is_success and $msg->ttl > 0
MC/DC0%0/2
not $msg->is_success and $msg->ttl > 0
not $msg->is_success
$msg->ttl > 0
Truth table0%0/3
not(A) and B
A= not $msg->is_successB= $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 | ▶ | if(ref $msg->cb eq 'CODE'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||||