python --发送移动云MAS短信
import pymysql
import time
import urllib3,certifi
import hashlib
import base64, json
#python发送移动云mas短信息(二平台、新平台)
content_a = {
"ecName": "********",#用户名,登录平台时的用户名
"apId": "********",#接口id,登录移动云mas后自己配置的,不是登录平台的账号
"secretKey": "********",#接口密码,,登录移动云mas后自己配置的,不是登录平台的密码
"mobiles": "151****9720,155****5930",#要发送至的手机号码,逗号隔开
"content": "测试短信",#短信内容
"sign": "****",#短信签名,从平台中下载
"addSerial": "",#为空
"mac": ""#空,程序生成
}
#生成md5的mac值,将ecName、apId、secretKey、mobiles、content、sign、addSerial进行无间隔拼接后生成32位的小写md5值
g_mac = hashlib.md5()
g_mac_cont = content_a['ecName'] + content_a['apId'] + content_a['secretKey'] + content_a['mobiles'] \
+ content_a['content'] + content_a['sign'] + content_a['addSerial']
print(g_mac_cont)
g_mac.update(g_mac_cont.encode('utf-8'))
content_a["mac"] = (g_mac.hexdigest()).lower()
#创建http_pool 池
http_pool = urllib3.PoolManager(cert_reqs='CERT_NONE')
#将content_a转为json字串后进行base64编码加密
encoding_content = base64.b64encode(json.dumps(content_a).encode('utf-8'))
strs = str(encoding_content,'utf-8')
print(json.dumps(content_a).encode('utf-8'))
print(strs)
#发送信息,更多接口见后面
#response = http_pool.request("POST", "https://112.35.10.201:28888/sms/submit",
response = http_pool.request("POST", "http://112.35.1.155:1992/sms/norsubmit",
body=strs, headers={'Content-Type': 'application/json','charset':'UTF-8'})
#读取响应
print(response.status)
print(response.data)
java文档如下: