• 0
  • 新人请关照

人已经吐血,写python七牛云短信接口4小时毫无线索?

python访问七牛云短信接口,接口文档完全看不明白。自己码了半小时完全无进展,快救救孩子吧

import requests
import time
import hmac
import base64
from hashlib import sha1
import json
#def hash_hmac(key, code, sha1):
    
def hash_hmac(key, code, sha1):
    hmac_code = hmac.new(key.encode("utf-8"), code.encode("utf-8"), sha1).digest()
    return       base64.b64encode(hmac_code).decode()

urlau="/v1/message/fulltext"
meth = "POST"
auData= {
 "\nHost:":" sms.qiniuapi.com",
 "\nContent-Type:":" application/json"
}
data = {
    "mobiles": "13693351446",
    "content": "cbjkasc",
    "template_type": "notification"
}

list1 =[]
for i in auData.items():
    if i[1]!=""and i[0]!="sign":
        list1.append("".join(i))
print(list1)
sort ="".join(list1)
austr = str(meth)+"\000"+str(urlau)+"\000"+"HTTP/1.1"+sort
print(austr)
key = "n8oxnmUGu9KpiWxine0_3gE2OySfe4EfXOgCS5sd"
encodedSign = hash_hmac(key,austr,sha1)
print(encodedSign)
url = "https://sms.qiniuapi.com/v1/message/fulltext"

header = {
"Host":"sms.qiniuapi.com",
"Authorization":"Qiniu "+"DaB1wAovX3so7_M7QEGSRL7XDAw4Qn_gbsidyyZ0"+":"+encodedSign,
"Content-Type": "application/json"
}

respon=requests.request('POST',url,data=data,headers=header)
print(respon.text)



    

`
返回结果如下所示:
Ku+gdPrXHrEtLlAIqBIPb10kQ4A=
['nHost: sms.qiniuapi.com', 'nContent-Type: application/json']
POST /v1/message/fulltext HTTP/1.1
Host: sms.qiniuapi.com
Content-Type: application/json
Vq2TN76f4c2bA6g/HB/ryocgXoI=
{"error":"BadToken","message":"Your authorization token is invalid","request_id":"1N9NB3Q231WkIBQW"}
文档链接如下所示:
https://developer.qiniu.com/s...

阅读 223
评论
    2 个回答
      七牛云问答
      合作问答

      七牛云 联合 SegmentFault 共同推出技术问答专区,为开发者们提供社区支持和帮助。在这里,你将直接获得...