1. Business Background
As a simple business scenario, end customers follow the official WeChat account of a car dealer, and then submit service requests to the dealer via WeChat. The service agents of the dealer could respond to the service requests, and the message will be posted to users in WeChat.
In this scenario, the end customers who follow the official WeChat account are created as individual customers in C4C, and service agents can reply to the service requests in C4C via Service Ticket.
- You should have already registered a WeChat official account with Subscription Account type from the WeChat Official Account platform, for registration,click here
- You should build up an intermediary app server to receive and send message between WeChat Server and C4C. This app server can be deployed on SAP Cloud Platform(SCP), or any 3rd party cloud platform. This blog is based on SCP.
- The related API should have been provided by C4C.
- The integration scenario in this case is mostly based on web service (use soap as protocol) instead of OData service, because some of the OData services are not available yet.
4. Integration process
4.1 flow chart
4.2 Process description
a. Users follow the official account. Intermediary servers collect the user information and create user profile in C4C system.
b. Users create customer account via WeChat official account. Intermediary servers receive the request and call API provided by C4C to create individual customer in system.
c. Users create tickets via WeChat official account. Intermediary servers receive the request and call API provided by C4C to create ticket in system.
d. Administrator replies ticket in C4C. The message will be pushed to intermediary servers with the interface configured in C4C and then be posted to users.
4.3 Development list
a. Development of intermediary server
b. Interface configuration in C4C Back-end
c. H5 web page of official account
5.1 intermediary servers
To build the intermediary server, take SCP for example. First, regarding how to build a node server in SCP, follow this help document. The following explains the main logic should be implemented in node server. For details, refer to sample code.
5.1.1 path of event listening
|GET||Validate the connection with WeChat server|
|POST||Receive the message and event from WeChat official account|
|/c4c/wechat||POST||Receive the message from C4C|
|/getWXWebToken||POST||Get the token and openid of WeChat official account|
|/web/create||POST||Handle the create request from web page of WeChat official account|
|/web/update||POST||Handle the update request from web page of WeChat official account|
|/web/get||GET||Handle the read request from web page of WeChat official account|
5.1.2 Handle the token of official account API
The token is necessary when calling WeChat API.
Developer need to get the token via link: https://api.weixin.qq.com/cgi-bin/token? grant_type=client_credential&appid=APPID&secret=APPSECRET
Each token will be expired in 2 hours. If the new token is generated, old one will be expired at once. In order to avoid multiple users refresh token at the same time to cause the token expired again and again, we suggests that the token should be stored in server and refreshed every 2 hours. All the users get the token from server.
5.1.3 Validate the WeChat official account server
In the administration page of official account, complete the configuration as below:
When the configuration is saved, WeChat server will post the token and some other parameters to the configured path ‘/wechat’ with http get mode. In the intermediary server, the same token will be encrypted and compared with the signature to implement the connection.
The parameters received by intermediary server are as below:
a. Sort ‘token’, timestamp’, ‘nonce’ in lexicographical order;
b. Concatenate the three parameters into string and complete Algorithm encryption;
c. Compare the encrypted string with signature to identify the request is from WeChat official account.
5.1.4 Generate the customized user menu in official account
Call the API of WeChat official account with POST mode ( use https as protocol)
‘ACCESS_TOKEN’ is the token stored in server in previous steps. Detail please refer to
5.2 Configuration in C4C
- Create mashup service
Create mashup service to interact with the intermediary server.
Url: <Your server address>/c4c/wechat
Other fields are filled as the screenshot.
- Create new channel with type “WeChat”.
This channel is the representation of related official account in C4C.
Please follow the below steps:
- Navigate to Administrator Service and Social Settings Social Media Channels.
- Click New.
- Select WeChat as the Social Media Channel .
- Enter the mashup Web service ID that you have created for the response.
- Enter your Chanel ID, Channel Name.
- Save your options.
- C4C API
It’s recommended to implement the interaction with OData service. But some interfaces must use web service instead (use SOAP as protocol) because not all related OData services are available. The related OData services are considered for future releases.
a. OData service
We provide standard OData service in C4C which contains several entities: https://<host_url>/sap/c4c/odata/v1/c4codataapi
Developer could handle CURD request with https://<host_url>/sap/c4c/odata/v1/c4codataapi/entityCollection
b. web service
Please configure and access the web service as below: