|
@ -1,10 +1,12 @@
|
|
|
package com.yihu.wlyy.service.weixin.applets;
|
|
|
|
|
|
import com.yihu.wlyy.util.SecretUtils;
|
|
|
import com.yihu.wlyy.util.http.HttpResponse;
|
|
|
import com.yihu.wlyy.util.http.HttpUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@ -17,22 +19,38 @@ import java.util.Map;
|
|
|
@Transactional
|
|
|
public class AppletsService {
|
|
|
|
|
|
private String appid = "wx47ecd9a6372e7c96";
|
|
|
private String appSecret ="9df49ebba7d5cdf8b9a77213bbf36807";
|
|
|
@Value("${applets.appId}")
|
|
|
private String appid;
|
|
|
@Value("${applets.appSecret}")
|
|
|
private String appSecret;
|
|
|
|
|
|
|
|
|
public Map<String,Object> checkApplets(String code) throws Exception{
|
|
|
public Map<String, Object> checkApplets(String code) throws Exception {
|
|
|
HttpUtils httpUtils = new HttpUtils();
|
|
|
Map<String,Object> param = new HashedMap();
|
|
|
param.put("appid",appid);
|
|
|
param.put("secret",appSecret);
|
|
|
param.put("js_code",code);
|
|
|
param.put("grant_type","authorization_code");
|
|
|
HttpResponse response = httpUtils.doGet("https://api.weixin.qq.com/sns/jscode2session",param);
|
|
|
Map<String, Object> param = new HashedMap();
|
|
|
param.put("appid", appid);
|
|
|
param.put("secret", appSecret);
|
|
|
param.put("js_code", code);
|
|
|
param.put("grant_type", "authorization_code");
|
|
|
|
|
|
HttpResponse response = httpUtils.doGet("https://api.weixin.qq.com/sns/jscode2session", param);
|
|
|
JSONObject rs = new JSONObject(response.getContent());
|
|
|
Map<String,Object> res = new HashedMap();
|
|
|
res.put("openid",rs.getString("openid"));
|
|
|
res.put("sessionKey",rs.getString("session_key"));
|
|
|
Map<String, Object> res = new HashedMap();
|
|
|
res.put("openid", rs.getString("openid"));
|
|
|
res.put("sessionKey", rs.getString("session_key"));
|
|
|
return res;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public JSONObject getWeRunData(String encryptedData, String iv, String sessionKey) throws Exception {
|
|
|
|
|
|
String result = SecretUtils.AES128CBCdecrypt(encryptedData, iv, appid, sessionKey);
|
|
|
|
|
|
JSONObject obj = new JSONObject(result);
|
|
|
|
|
|
JSONArray jsonArray = obj.getJSONArray("stepInfoList");
|
|
|
|
|
|
JSONObject jsonObject = (JSONObject) jsonArray.get(jsonArray.length()-1);
|
|
|
|
|
|
return jsonObject;
|
|
|
}
|
|
|
}
|