ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Forum AtoutFox : Re: WEB SERVICE   

Sujet

rss Flux RSS des derniers messages

Vous devez vous identifier pour pouvoir poser une question ou répondre.

mer. 02 décembre 2020, 22h54

Hamidou
Maroc Maroc

atoutfox.public.association

Re: WEB SERVICE


Cher ami Bonjour

1) l exemple ci-dessus comporte des erreurs syntaxiques
la syntaxe de js ou jason en brut n'est pas valable en foxpro

2) Regarde Chilkat ActiveX pour foxpro :
pour l usage de "https://api.whatsapp.com/send/"; en foxpro
réfères toi aux api :

https://www.example-code.com/foxpro/whatsapp.asp

ci-dessus l exemple de send de message vers un nmero wathsapp
*----------------------------------------------------------------------------------------
* (Visual FoxPro) WhatsApp - Send a Text Message
*--------------------------------------------------------------------
LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcId
LOCAL i
LOCAL lnCount_i

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loHttp = CreateObject('Chilkat_9_5_0.Http')

* Implements the following CURL command:

* curl -X POST https://example.com/v1/messages \
* -H "Authorization: Bearer your-auth-token" \
* -d '
* {
* "preview_url": false,
* "recipient_type": "individual",
* "to": "whatsapp-id-or-group-id",
* "type": "text",
* "text": {
* "body": "your-text-message-content"
* }
* }'

* Use the following online tool to generate HTTP code from a CURL command
* Convert a cURL Command to HTTP Source Code

* Use this online tool to generate code from sample JSON:
* Generate Code to Create JSON

* The following JSON is sent in the request body.

* {
* "preview_url": false,
* "recipient_type": "individual",
* "to": "whatsapp-id-or-group-id",
* "type": "text",
* "text": {
* "body": "your-text-message-content"
* }
* }

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateBool("preview_url",0)
loJson.UpdateString("recipient_type","individual")
loJson.UpdateString("to","whatsapp-id-or-group-id")
loJson.UpdateString("type","text")
loJson.UpdateString("text.body","your-text-message-content")

* Adds the "Authorization: Bearer your-auth-token" header.
loHttp.AuthToken = "your-auth-token"

loResp = loHttp.PostJson3("https://example.com/v1/messages","application/json",loJson)
IF (loHttp.LastMethodSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
CANCEL
ENDIF

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loResp
RELEASE loHttp
RELEASE loJson
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF

RELEASE loResp

* Sample JSON response:
* (Sample code for parsing the JSON response is shown below)

* {
* "messages": [
* {
* "id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU"
* }
* ]
* }

* Sample code for parsing the JSON response...
* Use the following online tool to generate parsing code from sample JSON:
* Generate Parsing Code from JSON

i = 0
lnCount_i = loJResp.SizeOfArray("messages")
DO WHILE i < lnCount_i
loJResp.I = i
lcId = loJResp.StringOf("messages[i].id")
i = i + 1
ENDDO

RELEASE loHttp
RELEASE loJson
RELEASE loSbResponseBody
RELEASE loJResp

* bon courage



Permalink : http://www.atoutfox.org/nntp.asp?ID=0000019752
19 708 messages dans le forum • Liste complète des messages

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2021.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3