本文为您介绍Python调用SendMessageToGlobe发送短信到国际地区的程序样例。

注意事项

参考这个示例您需要注意以下几点:
  • 构造AcsClient时,第三个参数(regionId)必须为cn-hangzhou,请勿修改。
  • domain必须为dysmsapi.aliyuncs.com,请勿修改。
  • version必须为2017-05-25,请勿修改。

编写样例程序

#!/usr/bin/env python
#coding=utf-8
import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')
request = CommonRequest()
request.set_accept_format('json')
request.set_domain('dysmsapi.aliyuncs.com')
request.set_method('POST')
request.set_version('2017-05-25')
request.set_action_name('SendMessageToGlobe')
request.add_query_param('To', '6281****07451')
request.add_query_param('From', '1234')
request.add_query_param('Message', 'Have a test.')
request.add_query_param('Type', 'OTP')
response = client.do_action(request)
# python2: print(response)
print(str(response, encoding = 'utf-8'))