package com.palmnest.service.ws;

import com.alibaba.fastjson.JSONObject;
import com.palmnest.application.core.util.HttpKit;
import com.palmnest.application.core.util.PropertiesKit;
import com.palmnest.application.core.util.StringUtil;
import lombok.extern.slf4j.Slf4j;

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

/**
 * 欧法信商城系统接口实现类客户端
 *
 * @author yubing
 * @since 2017-08-28
 */
@Slf4j
public class OFXShopSysClient {


	private static String key          = PropertiesKit.readPropertiesValue("key", "wechat.properties");
	private static String changeTelUrl = PropertiesKit.readPropertiesValue("changeTelUrl", "wechat.properties");

	/**
	 * 更改会员手机号码
	 *
	 * @param oldTel 原始手机号码
	 * @param newTel 新的手机号码
	 * @return true-修改成功，false-修改失败
	 */
	public static boolean changeTel(String oldTel, String newTel) {
		Map<String, String> paramsMap = new HashMap<String, String>();
		paramsMap.put("oldTel", oldTel);
		paramsMap.put("newTel", newTel);

		String timestamp = System.currentTimeMillis() + "";
		String sign      = StringUtil.md5(oldTel + timestamp + key);
		paramsMap.put("timestamp", timestamp);
		paramsMap.put("sign", sign);

		log.info("------- changeTel -------");
		log.info("oldTel:" + oldTel);
		log.info("newTel:" + newTel);
		log.info("timestamp:" + timestamp);
		log.info("sign:" + sign);
		String resultJsonStr = HttpKit.http(changeTelUrl, paramsMap, "POST");
		log.info("resultJsonStr:" + resultJsonStr);

		Map<String, String> resultMap = JSONObject.parseObject(resultJsonStr, Map.class);
		if ("1000".equals(resultMap.get("errcode"))) {
			return true;
		} else {
			return false;
		}
	}

}
