|
|
|
@ -8,11 +8,19 @@ import com.kiisoo.ic.common.BaseController;
|
|
|
|
|
import com.kiisoo.ic.common.utils.httpClientUtil.HttpClientUtil;
|
|
|
|
|
import com.kiisoo.ic.common.utils.httpClientUtil.HttpResult;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.shiro.codec.Base64;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.security.spec.AlgorithmParameterSpec;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
@ -53,10 +61,15 @@ public class WechatController extends BaseController {
|
|
|
|
|
|
|
|
|
|
HttpResult data = HttpClientUtil.httpGet(urlPath.toString());
|
|
|
|
|
//http返回参数
|
|
|
|
|
if (JSONObject.parseObject(data.getMessage()).get("errcode").equals("0")) {
|
|
|
|
|
if (data.getCode() == 200) {
|
|
|
|
|
String openid = JSONObject.parseObject(data.getMessage()).get("openid").toString();
|
|
|
|
|
String sessionKey = JSONObject.parseObject(data.getMessage()).get("session_key").toString();
|
|
|
|
|
String unionid = JSONObject.parseObject(data.getMessage()).get("unionid").toString();
|
|
|
|
|
|
|
|
|
|
String unionid = "";
|
|
|
|
|
if (JSONObject.parseObject(data.getMessage()).get("unionid") != null) {
|
|
|
|
|
unionid = JSONObject.parseObject(data.getMessage()).get("unionid").toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.put("openId", openid);
|
|
|
|
|
result.put("sessionKey", sessionKey);
|
|
|
|
@ -68,4 +81,43 @@ public class WechatController extends BaseController {
|
|
|
|
|
}
|
|
|
|
|
return fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解密并且获取用户手机号码
|
|
|
|
|
*
|
|
|
|
|
* @param encrypdata
|
|
|
|
|
* @param ivdata
|
|
|
|
|
* @param sessionkey
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping(value = "encode", method = RequestMethod.GET)
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public Map<String, Object> deciphering(@RequestParam("encrypdata") String encrypdata, @RequestParam("ivdata") String ivdata, @RequestParam("sessionkey")String sessionkey) {
|
|
|
|
|
|
|
|
|
|
byte[] encrypData = Base64.decode(encrypdata);
|
|
|
|
|
byte[] ivData = Base64.decode(ivdata);
|
|
|
|
|
byte[] sessionKey = Base64.decode(sessionkey);
|
|
|
|
|
String str = "";
|
|
|
|
|
try {
|
|
|
|
|
str = decrypt(sessionKey, ivData, encrypData);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
System.out.println(str);
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("phone", str);
|
|
|
|
|
return data(map);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String decrypt(byte[] key, byte[] iv, byte[] encData) throws Exception {
|
|
|
|
|
AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
|
|
|
|
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
|
|
|
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
|
|
|
|
|
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
|
|
|
|
//解析解密后的字符串
|
|
|
|
|
return new String(cipher.doFinal(encData), "UTF-8");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|