package com.chinacreator.process.util.fakeid;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

/**
 * 通过接口查询电商伪码
 * 
 * @author 科创·毛燕龙
 * @datetime 2019年4月11日 上午9:22:05
 */
public class FakeidUtil {
	
//	public static String baseurl="http://123.125.99.8:9001/api";
//	public static String baseurl="http://123.125.99.7:10004/api";
	public static final String baseurl="http://123.125.99.7:9003/api";
//	public static final String baseurl="http://netid.10010.com:9002/api";
	
//	public static final String user="000000";
//	public static final String user="000034";
	public static final String user="000025";
	
//	public static final String pwd="test123";
//	public static final String pwd="jE6N6o3BVs14";
	public static final String pwd="8MwkN8wy7tr4";
	
	public static final String service="1";
	
	public static final String function="7";
	
	public static String getFakeidFromUnicom(String userid,String spid){
		try {
			Date curdate= new Date();
			
			String tick=(curdate.getTime()/1000)+"";
			String key=MD5.MD5Encode(user+tick+pwd).substring(0,16);
			
			Map<String,String> param = new HashMap<String,String>();
			param.put("user",user);
			param.put("tick",tick);
			param.put("key",key);
			param.put("service",service);
			param.put("function",function);
			param.put("mobile","86"+userid);
			
			String url = URLUtil.mapToUrl(baseurl,param);
			
			String resp = URLUtil.get(url);
			System.out.println(url+"###"+resp);
			
			JSONObject resultObject = JSONObject.fromObject(resp);
    		String result = resultObject.getString("result");
    		if("0".equals(result)){
    			return resultObject.getString("pcode");
    		}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	
	public static void main(String[] args) {
		String dd = FakeidUtil.getFakeidFromUnicom("18610560885", null);
		System.out.println(dd);
	}

}
