After the app is created, you'll see following app admin page. Please note that this is only a virtual app (a WeChat Work App configuration), you need to integrate these WeChat Work configuration data into SAP Mobile Services and your real CF application. To do this, you need to fetch some critical values from WeChat work app admin page:
Now open your SAP Mobile Services Cockpit and go to "Micro App" tab from the left menu:You can create your application with "New" button. In the Mobile Services application creating window, please enter the application ID, application name, WeChat Work account Corp ID (from Step 1), WeChat Work app Agent Id (also from Step 1)After the Mobile Services application is created and ready, you need to configure "Mobile Micro App" and "Mobile Connectivity" under the Assigned Features to make it work.
Please note that this Mobile Services application is also a virtual configuration, you need to integrate this application with real CF application and WeChat work app configuration together.In the "Mobile Micro App" configuration page, you need to enter the App Secret, Token and EncodingAESKey which we saved from WeChat Work admin page from Step 1.In the "Service Keys" tab, please manually create a push service key (auto-generated random key string) with "+" button:This service key is extremely important for you in your Java application deployed to CF later if you want to use the WeChat message push feature. See more service keys introduction here.
You can get the WeChat message push API from the "APIs" tab of the mobile services application just like following picture (API - WeChat Push). You need to call this API with service key header and JSON message payload which will be discussed in next step.
Note: Regarding the "Message Handler Endpoint" field in "Mobile Micro App" configuration and "Mobile Connectivity" endpoint configuration, We'll set this later after we deployed the real application to SAP BTP CF.
The following picture simply shows how the WeChat work integrates with SAP BTP via SAP Mobile Services MicroApp:
Here I use SAP WebIDE to create a Simple Java Spring Boot "TimeOff" application as an example. Before start, we need to enable the WebIDE Mobile Services extension, SAP is supporting micro app features in this extension to help developers on faster development of micro apps.
After that you will be able to create Blank WeChat Micro App in Mobile Services extension (I named it "TimeOffDemo" here), and configure the Cloud Foundry Endpoint/Org/Space, and your Mobile Services application id which was created in Step 2.
Once the project is created and ready, you can right click on the project TimeOffDemo and create a new Java Module. To make the development easier, Mobile Services extension provides a Micro App Message Handler module here which contains most of the basic WeChat message handling Java code.
In the project, we saw the com.sap.microapp.messaging package is already auto-generated which contains basically most of the required WeChat message handling functions. Here are some explanation for the main packages:
$.ajax({
url: "/timeoff/leaverequest",
contentType: "application/json;charset=UTF-8",
data: JSON.stringify(postData),
type: "POST",
success: function(result){ //... },
error: function(jqXHR, textStatus, errorThrown) {}
});
// push simple text to user P000001
{
"notification": {
"wechat": {
"createtime": "2019-12-17T06:24:26.451Z",
"text": {
"content": "hello world!"
},
"msgtype": "text"
}
},
"users": ["P000001"]
}
// upload base64 encoded file and push it to user P000001
{
"notification": {
"wechat": {
"createtime": "2019-12-17T06:52:23.417Z",
"file": {
"media_file_encoded": "data:application/x-zip-compressed;base64,XXXXXXXXXX",
"media_file_name": "abc.zip"
},
"msgtype": "file"
}
},
"users": ["P000001"]
}
After the you implement your business logic, you can deploy your project to SAP BTP Cloud Foundry as CF application. In WebIDE Mobile Services extension, it provides a simple button to deploy to Mobile Services as CF application:
In the "Deploy Micro App" wizard, Select your Mobile Services application created from Step 2. You don't need to check "Publish to Mobile service" here because we will manually create Mobile Services endpoints later which is more flexible.
Once the deployment is finished, you should see your real application running in your SAP BTP Cloud Foundry space:
This is a Java application, it talks to WeChat Server and Mobile Services together to accomplish your business requirement, e.g. process receiving WeChat message from end users, push different kinds of WeChat messages to end users, etc.
What is a CF application and How to maintain it is out of scope of this tutorial. The CF application routes as marked in the following picture is the main entrance of this Java application.
Firstly, open your SAP Mobile Services Cockpit and go to "Mobile Connectivity" configuration, and create the required destination endpoints:
you need to create at least the destination to receive WeChat message from WeChat Server, here in my application, it is named "chat", and the URL is <CF application routes>/OnMessage which matches the message receiving controller (CF application routes is marked in the end of Step 3). I also created a "timeoff" destination which is equal to the CF application routes, this is used for UI JavaScript code handling to make the HTTP call.
Then, go to the "Mobile Micro App" and complete the last empty field "Message Handler Endpoint", select the destination "chat" you just created, and the micro app message handler URL will be auto-generated for you:
Afterwards, go back to WeChat Work admin page of your WeChat application, Add trusted domain name for your SAP Mobile Services application by clicking "Apply for domain name verification". This is an important step because we need to let WeChat Work trust our Mobile Services domains otherwise you'll see some errors like "domain is not trusted" when accessing the TimeOff demo. The trusted domain URL to be filled can be fetched from the "Server API" from SAP Mobile Services Cockpit MicroApp application "APIs" tab.
Last, go to the "API enabled to receive messages" and fill in the URL configuration of "Receive messages via API":
Paste the Token and EncodingAESKey you created from the Step 1, paste the micro app message handler URL to the "URL" field, and then click "Save".
How my demo works is shown in the left part of follow picture:
My App TimeOffApp receives "create" WeChat messages from WeChat Work end users and creates a leave request in back-end. Then I can communicate with TimeOffApp through chatting, e.g. setting start/end date of leave request, or reason of the request, etc. After entering "submit", the TimeOffApp will notify the approver of the TimeOff that any leave request is created (see right part of the picture). After the approver approves the request, TimeOffApp send a text-card message to the requester as result notification.
I also created a index page in TimeOffApp for requester to create leave request in UI page, based on the WeChat Work feature, you can configure a homepage button to open any index pages in WeChat Application Admin page, e.g. the TimeOff button to open TimeOffApp UI homepage:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
10 | |
9 | |
8 | |
7 | |
7 | |
7 | |
7 | |
6 |