i need some help, am trying to code Alibaba cloud sms
#!/usr/bin/perl -w use LWP; use URI; use Net::SSL; my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, ); $ua->agent("MyApp/0.1"); my $url = "https://dysmsapi.aliyuncs.com"; my $params = [ RegionId => '1', PhoneNumbers => '4324234', SignName => + 'fghgfhg', TemplateCode => 'fghgfh']; my $uri = URI->new(); $uri->query_form(@$params); $urlparam = $uri->as_string; my $req = HTTP::Request->new(POST=>$url); $req->header('Content-Type' => 'application/json; charset=UTF-8'); $req->header('access_key_id' => 'sdsadasd'); $req->header('access_key_secret' => 'asdasdsa'); $req->header('api_version' => '2017-05-25'); $req->content($urlparam); print "Content-type: text/html\n\n"; my $res = $ua->request($req); if ($res->is_success) { print $res->content; } else { #print whole resluts from post print $res->content; print "\n"; #print error code print $res->status_line; }
am getting this error: FC41FAB2-2735-4495-A072-54850CD00A4Edysmsapi.aliyuncs.comInvalidVersionSpecified parameter Version is not valid. 400 Bad Request
am trying to make it like these example codes in php, python and ruby. because aliabab cloud sms doesn't have it in perl
PYTHON #!/usr/bin/env python #coding=utf-8 from aliyunsdkcore.client import AcsClient from aliyunsdkcore.request import CommonRequest client = AcsClient('<accessKeyId>', '<accessSecret>', 'default') request = CommonRequest() request.set_accept_format('json') request.set_domain('dysmsapi.aliyuncs.com') request.set_method('POST') request.set_protocol_type('https') # https | http request.set_version('2017-05-25') request.set_action_name('SendSms') request.add_query_param('RegionId', "default") request.add_query_param('PhoneNumbers', "7766") request.add_query_param('SignName', "iiuy") request.add_query_param('TemplateCode', "jkk") response = client.do_action(request) # python2: print(response) print(str(response, encoding = 'utf-8')) RUBY # gem install aliyunsdkcore require 'aliyunsdkcore' client = RPCClient.new( access_key_id: '<accessKeyId>', access_key_secret: '<accessSecret>', endpoint: 'https://dysmsapi.aliyuncs.com', api_version: '2017-05-25' ) response = client.request( action: 'SendSms', params: { "RegionId": "default", "PhoneNumbers": "7766", "SignName": "iiuy", "TemplateCode": "jkk" }, opts: { method: 'POST' } ) print response PHP <?php use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; // Download:https://github.com/aliyun/openapi-sdk-php // Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/ +README.md AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>') ->regionId('cn-hangzhou') // replace regionId +as you need ->asDefaultClient(); try { $result = AlibabaCloud::rpc() ->product('Dysmsapi') // ->scheme('https') // https | http ->version('2017-05-25') ->action('SendSms') ->method('POST') ->host('dysmsapi.aliyuncs.com') ->options([ 'query' => [ 'RegionId' => "default", 'PhoneNumbers' => "7766", 'SignName' => "iiuy", 'TemplateCode' => "jkk", ], ]) ->request(); print_r($result->toArray()); } catch (ClientException $e) { echo $e->getErrorMessage() . PHP_EOL; } catch (ServerException $e) { echo $e->getErrorMessage() . PHP_EOL; }
In reply to alibaba cloud sms api by bigup401
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |