우맹 푸시 ios 서버

3385 단어
import java.io.IOException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

//import net.sf.json.JSONObject;
import com.alibaba.dubbo.common.json.JSONObject;

import org.apache.log4j.Logger;

import com.alibaba.dubbo.common.json.JSON;
import com.alibaba.dubbo.common.json.ParseException;

/**
 * ios 
 * @author shanl
 *
 */
public class UMengPushIOSImpl implements UMengPushPlatform{
	private Map<String,String> pushParams = new HashMap<>();
	static final Logger logger = Logger.getLogger(UMengPushIOSImpl.class);
	
	public UMengPushIOSImpl(){
		pushParams.put("method", Utils.UMENG_METHOD);
		pushParams.put("url", Utils.UMENG_URL);
		pushParams.put("appkey.tech", "555b1d7867e58e104a000cd3");
		pushParams.put("appMasterSecret.tech", "9d6irworjocdanrgtrzhuspnauojuqnt");
		pushParams.put("appkey.user", "555b1e4367e58e3482001d7b");
		pushParams.put("appMasterSecret.user", "th9ablyqta3g6oneqsfylx97dvxraxyy");
	}
	
	
	public boolean custom(int userType,
			String alias,String alias_type,
			String title,String text,
			Map<String,Object> extraParams){
		Map<String,Object> resMap = new HashMap<>();
		JSONObject data = new JSONObject();
		data.put("appkey", pushParams.get("appkey."+Utils.toUsertypeStr(userType)));
		data.put("timestamp", System.currentTimeMillis()+"");
		data.put("type", "customizedcast");
		data.put("alias", alias);
		data.put("alias_type", alias_type);
		
		JSONObject payload  = new JSONObject();
		payload.put("aps", title);
		payload.put("text", text);
		payload.putAll(extraParams);
		data.put("payload", payload);
		
		JSONObject aps  = new JSONObject();
		aps.put("alert", title);
		payload.put("aps", aps);
		
		JSONObject policy = new JSONObject();
		policy.put("expire_time", Utils.getExpireTime());
		data.put("policy", policy);
		
		data.put("description", "description");
		data.put("production_mode", "false");
		
		try {
			String post_body = JSON.json(data);
			String sign = Utils.sign(new String[]{
					pushParams.get("method"),
					pushParams.get("url"),
					post_body,
					pushParams.get("appMasterSecret."+Utils.toUsertypeStr(userType))
			});
			
			//{"ret":"SUCCESS","data":{"msg_id":"ul62380143320937907000"}}
			String res = Utils.sendMsg(pushParams.get("url"), 
					sign,
					post_body);
			resMap = JSON.parse(res, Map.class);
			logger.info( "userType:"+Utils.toUsertypeStr(userType)
					+",
appkey:"+pushParams.get("appkey."+Utils.toUsertypeStr(userType)) +",appMasterSecret:"+pushParams.get("appMasterSecret."+Utils.toUsertypeStr(userType)) +",
"+pushParams.get("url")+"?sign="+sign +",
post_body:"+post_body +",
resMap:"+resMap); } catch (IOException|ParseException e) { throw new RuntimeException(e); } return "SUCCESS".equals(resMap.get("ret")+""); } public void setPushParams(Map<String,String> pushParams){ this.pushParams = pushParams; } }

좋은 웹페이지 즐겨찾기