|
|
|
package com.hai.config;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.hai.common.pay.util.sdk.WXPayConstants;
|
|
|
|
import com.hai.common.utils.HttpsUtils;
|
|
|
|
import com.hai.common.utils.MD5Util;
|
|
|
|
import com.hai.common.utils.ResponseMsgUtil;
|
|
|
|
import com.hai.model.ResponseData;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author hurui
|
|
|
|
* @version 1.0
|
|
|
|
* @ClassName QianZhuConfig
|
|
|
|
* @description: 千猪接口配置
|
|
|
|
* @date 2021/7/5 14:18
|
|
|
|
*/
|
|
|
|
public class QianZhuConfig {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成Token
|
|
|
|
* @param platformUniqueId 用户唯一id
|
|
|
|
* @param nickname 昵称
|
|
|
|
* @param mobile 电话号码
|
|
|
|
* @return Token
|
|
|
|
*/
|
|
|
|
public static JSONObject getToken(String platformUniqueId,String nickname,String mobile) throws Exception {
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
map.put("platformId", CommonSysConst.getSysConfig().getQinzhuPlatformId());
|
|
|
|
map.put("timestamp", new Date().getTime());
|
|
|
|
map.put("platformUniqueId", platformUniqueId);
|
|
|
|
map.put("nickname", nickname);
|
|
|
|
map.put("mobile", mobile);
|
|
|
|
map.put("sign", MD5Util.encode(generateSignature(map,CommonSysConst.getSysConfig().getQinzhuSecret()).getBytes()).toLowerCase());
|
|
|
|
return HttpsUtils.doGet(CommonSysConst.getSysConfig().getQinzhuUrl()+"/api/v2/platform/getToken", map);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成签名
|
|
|
|
* @param data 数据
|
|
|
|
* @param key 秘钥app_secret
|
|
|
|
* @return 加密结果
|
|
|
|
*/
|
|
|
|
public static String generateSignature(final Map<String, Object> data, String key){
|
|
|
|
Set<String> keySet = data.keySet();
|
|
|
|
String[] keyArray = keySet.toArray(new String[keySet.size()]);
|
|
|
|
Arrays.sort(keyArray);
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
for (String k : keyArray) {
|
|
|
|
if (k.equals(WXPayConstants.FIELD_SIGN)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (StringUtils.isBlank(sb.toString())) {
|
|
|
|
sb.append(k).append("=").append(data.get(k));
|
|
|
|
} else {
|
|
|
|
sb.append("&").append(k).append("=").append(data.get(k));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sb.append(key);
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
}
|