Method of Accessing WeChat via Messaging Interface
I. Overview
When binding the URL and Token of other developers in the WeChat Developer Backend, if you want to simultaneously use Udesk services, you can achieve this by docking with the Udesk messaging interface through a server.
By docking with the Udesk messaging interface server, both message reception and sending go through the server. (For WeChat, special optimizations have been made. Images that comply with WeChat specifications can be directly generated by obtaining a token without the need for the server to upload to WeChat again.)
Administrators log in to the Udesk backend [Management Center - Instant Messaging - Message Interface Access]
II. Test whether the message reception channel is normal
Test whether the interface is unblocked:
curl https://xxxx.udesk.cn/spa1/im_callback/test?number=13574221234&email=894733082@qq.com×tamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7
Incoming parameters
number=13574221234&email=894733082@qq.com×tamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7
Parameter Description
Parameter Name | Description |
---|---|
number | Phone number |
timestamp | Timestamp |
sign | Result of generating md5 based on the previous parameters |
Sign Generation Method
- sign = md5(number=13574221234&email=894733082@qq.com×tamp=20151124141451&secret).upper
- Convert to uppercase after md5
- secret: Corresponding to the "KEY" of the message push server address in [Management Center - Instant Messaging - Message Interface Access]
Return parameters
Success: { "success": true }
Failure:
{
"success": false,
"msg": "sign verification failed"
}
Parameter Name | Description |
---|---|
success | True/false, request successful/failed |
msg | Result explanation in string format |
III. Receiving Message Interface
Customer sends a message to customer service
1. Receiving Text Messages
Receiving Message Interface
POST http://xxxx.udesk.cn/spa1/im_callback?number=13574221234&email=894733082@qq.com×tamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7
Request Parameters (Request Body) Example
<xml>
<FromUserName>openid</FromUserName>
<Number>phone number</Number>
<Email>894733082@qq.com</Email>
<Content>this is a test</Content>
<CreateTime>1548348776</CreateTime>
<MsgType>text</MsgType>
<MsgId>1548348777</MsgId>
</xml>
Parameter Description
Parameter Name | Description |
---|---|
FromUserName | Sender account (an OpenID) |
Number | Customer mobile number or phone |
Customer email | |
Content | Message content |
CreateTime | Message creation time (integer) |
MsgType | text |
MsgId | Message ID, 64-bit integer |
2. Receiving Image Messages
Receiving Message Interface
POST http://xxxx.udesk.cn/spa1/im_callback?number=13574221234&email=894733082@qq.com×tamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7
Request Parameters (Request Body) Example
<xml>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<Number>phone number</Number>
<Email>894733082@qq.com</Email>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<PicUrl><![CDATA[this is a url]]></PicUrl>
<MediaId><![CDATA[media_id]]></MediaId>
<MsgId>1234567890123456</MsgId>
</xml>
Parameter Description
Parameter Name | Description |
---|---|
FromUserName | Sender account (an OpenID) |
Number | Customer mobile number or phone |
Customer email | |
CreateTime | Message creation time (integer) |
MsgType | image |
PicUrl | Image link |
MediaId | Media ID of the image message, can be used to call the multimedia file download interface to pull data. |
MsgId | Message ID, 64-bit integer |
3. Receiving Voice Messages
Receiving Message Interface
POST http://xxxx.udesk.cn/spa1/im_callback?number=13574221234&email=894733082@qq.com×tamp=20151124141451&sign=07131700A29AD987F5D9F0463CE7EFC7
Request Parameters (Request Body) Example
<xml>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<Number>phone number</Number>
<Email>894733082@qq.com</Email>
<CreateTime>1357290913</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<MediaId><![CDATA[media_id]]></MediaId>
<Format><![CDATA[Format]]></Format>
<MsgId>1234567890123456</MsgId>
</xml>
Parameter Description
Parameter Name | Description |
---|---|
FromUserName | Sender account (an OpenID) |
Number | Customer mobile number or phone |
Customer email | |
CreateTime | Message creation time (integer) |
MsgType | Voice is voice |
MediaId | Media ID of the image message, can be used to call the multimedia file download interface to pull data. |
Format | Voice format, amr |
MsgId | Message ID, 64-bit integer |
4. Response Result When Receiving Messages
Parameter Description
Parameter Name | Description |
---|---|
status | Customer service status, queuing/chatting/offline/unknown (queueing/chatting/offline/unknown error) |
turn | Position in the queue |
agent_name | Customer service name |
msg | string format message |
Example
{
"status": "chatting",
"turn": 0,
"agent_name": "Test Customer Service 1",
"msg": "Test Customer Service 1 is serving you!"
}