In order to better improve users’ game experience, wechat provides customer service API. An icon button is created in the game, which can be clicked to open the customer service session window. Users can send text, language and other information, and customer service personnel can see it in the background and reply.

The front-end is very simple code:

public static openKeFu(success:Function){ let wx = window["wx"]; if(wx){ if(! Wx. OpenCustomerServiceConversation) {return MyAlertKnife. ShowTip (" WeChat version is too low, you suggest to upgrade ~ "); } wx.openCustomerServiceConversation({}); }}Copy the code

Take a closer look at the parameter sendMessagePath of this API, you can define different values, combined with the rule that customer service can reply messages within 48 hours, with server data processing, you can achieve more advanced functions. Look at the code again:

public static openKeFu(success:Function){ let wx = window["wx"]; if(wx){ if(! Wx. OpenCustomerServiceConversation) {return MyAlertKnife. ShowTip (" WeChat version is too low, you suggest to upgrade ~ "); } let obj = { showMessageCard: true, sessionFrom: "game", sendMessagePath: "gift", sendMessageTitle: "My main point COINS", sendMessageImg: "http://www.qq.com/shareicon/kefu.jpg", success: success}; wx.openCustomerServiceConversation(obj); }}Copy the code

You can see that the above code added several parameters, to send a “gold” custom card to the customer service window. And then what? Does this make sense? B: of course! This message can achieve the function of drainage to promote activity! Please look down.

Development ideas, this is the key: 2. The client sends a message to the customer service window, and the message is forwarded to the server. The server inserts a field into the user according to the type. Users who have sent customer service messages can receive rewards in the game. 4. The background of the customer service server can reply and push to users who have sent messages within 48 hours. In this way, customer service servers can push customized messages to users every day! When the player has not opened the game today, there is a push message to remind the player to open the game again! After testing in a few games, this feature increased retention by 2-5 percent.

First, we need to configure “message push”, enter the applets platform, choose “Settings” -> “Development Settings” -> “Message Push” -> click “Enable”.After the function is enabled, you need to fill in the URL (that is, the URL to process the message reply message, which can be used in PHP or other languages). Token is particularly key, so it is not random to fill in. You need to record the Token string sent by wechat on the server. Other options can be selected as appropriate based on business requirements and development habits.The code for obtaining the Token is:

$signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; $tmpArr = array($TOKEN, $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }else{ return false; }Copy the code

After the obtained Token is configured in the figure above, click Submit, and the configuration is completed after verification is successful.

The server then receives a customer service message push and can write the business processing logic.