| 1 | package Plack::App::Openqq::SendDiscussMessage; | ||
| 2 | use parent qw(Plack::Component); | ||
| 3 | use URI::Escape qw(uri_unescape); | ||
| 4 | use JSON; | ||
| 5 | use Encode; | ||
| 6 | sub call{ | ||
| 7 | my $self = shift; | ||
| 8 | my $client = $self->{client}; | ||
| 9 | my $env = shift; | ||
| 10 | my %query_string; | ||
| 11 | for my $query_string (split(/&/,$env->{QUERY_STRING} )){ | ||
| 12 | my($key,$value) = split /=/,$query_string; | ||
| 13 | $query_string{$key} = $value; | ||
| 14 | } | ||
| 15 | my $uin = $query_string{uin} || $query_string{did}; | ||
| 16 | my $content = uri_unescape($query_string{content}); | ||
| 17 | |||
| 18 | return sub { | ||
| 19 | my $responder = shift; | ||
| 20 | my $msg = $client->create_discuss_msg(to_uin=>$uin,content=>$content); | ||
| 21 | $msg->{cb} = sub{ | ||
| 22 | my($msg,$is_success,$status) = @_; | ||
| 23 | my $res = { | ||
| 24 | msg_id => $msg->{msg_id}, | ||
| 25 | code => $is_success, | ||
| 26 | status => decode("utf8",$status), | ||
| 27 | }; | ||
| 28 | my $json = JSON->new->utf8->encode($res); | ||
| 29 | $responder->([ | ||
| 30 | 200, | ||
| 31 | ['Content-Type' => 'text/plain'], | ||
| 32 | [$json], | ||
| 33 | ]); | ||
| 34 | }; | ||
| 35 | $client->send_discuss_message($msg); | ||
| 36 | }; | ||
| 37 | |||
| 38 | } | ||
| 39 | 1; |