下面是我想通过 python 或通过java 或 python 在我的代码库中实现的邮递员请求。
内容类型是application/x-www-form-urlencoded
目前我正在尝试使用python。
下面是我正在尝试但不工作的代码。
import requests
import sys
import json
def sendMessage(contact, content):
url = "https://api.gupshup.io/sm/api/v1/msg"
contact = contact.replace("91", "")
print("conatct is", contact)
print("content is", content)
payload = json.dumps({
"channel": "whatsapp",
"source": "917834811114",
"destination": '91'+contact,
# "message": {"type":"text","text":content},
"message": {
"isHSM": "true",
"type": "text",
"text": "Hi John, your order is confirmed and will be delivered to you by 15 Feb"
},
"src.name": "rubixds"
})
# payload = 'channel=whatsapp&source=917834811114&destination='+'91'+contact + \
# '&message=%7B%22type%22%3A%22text%22%2C%22text%22%3A%22%0A%0A' + \
# content+'%0A%0A%22%7D&src.name=rubixds'
params = {'message': {
"isHSM": "true",
"type": "text",
"text": "Hi John, your order is confirmed and will be delivered to you by 15 Feb"
}}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'apikey': 'xxx'
}
response = requests.request(
"POST", url, headers=headers, params=params, data=payload)
print(response.text)
感谢我通过java 8 (spring boot) 或 python 获得的所有帮助。