以下は、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)
問題を下回っています。メッセージ パラメータが API によって読み取られていないようです。
Java 8(Spring Boot)またはPythonを介してこれを行うことができるすべての助けをいただければ幸いです。