View Javadoc
1   package com.foxinmy.weixin4j.wxa.api;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import com.foxinmy.weixin4j.tuple.NotifyTuple;
7   import com.foxinmy.weixin4j.wxa.model.custommessage.Command;
8   import com.foxinmy.weixin4j.wxa.model.custommessage.CustomMessage;
9   
10  /**
11   * Adapters for {@link CustomMessageApi}.
12   *
13   * @since 1.8
14   */
15  final class CustomMessageAdapters {
16  
17  	private CustomMessageAdapters() {
18  	}
19  
20  	public static Map<String, Object> toMap(CustomMessage customMessage) {
21  		final NotifyTuple tuple = customMessage.getTuple();
22  		final String msgType = tuple.getMessageType();
23  
24  		final Map<String, Object> params = new HashMap<String, Object>(3);
25  		params.put("touser", customMessage.getToUser());
26  		params.put("msgtype", msgType);
27  		params.put(msgType, tuple);
28  
29  		return params;
30  	}
31  
32  	public static Map<String, String> toMap(String toUser, Command command) {
33  		final Map<String, String> params = new HashMap<String, String>(2);
34  		params.put("touser", toUser);
35  		params.put("command", command.toString());
36  		return params;
37  	}
38  }