Commit f09116ec authored by 曹盼盼's avatar 曹盼盼

修改微信小程序授权登录的session_key在后端解密

parent ad771642
...@@ -24,10 +24,12 @@ import com.yeejoin.amos.feign.privilege.model.IdPasswordAuthModel; ...@@ -24,10 +24,12 @@ import com.yeejoin.amos.feign.privilege.model.IdPasswordAuthModel;
import com.yeejoin.amos.feign.systemctl.Systemctl; import com.yeejoin.amos.feign.systemctl.Systemctl;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.ibatis.builder.MapperBuilderAssistant; import org.apache.ibatis.builder.MapperBuilderAssistant;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
...@@ -39,12 +41,20 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil; ...@@ -39,12 +41,20 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.security.AlgorithmParameters;
import java.security.NoSuchProviderException;
import java.security.Security;
import java.util.*; import java.util.*;
import static com.mysql.cj.jdbc.interceptors.SessionAssociationInterceptor.getSessionKey;
@Service @Service
@Slf4j @Slf4j
public class TzsAppService { public class TzsAppService {
...@@ -112,6 +122,11 @@ public class TzsAppService { ...@@ -112,6 +122,11 @@ public class TzsAppService {
RedisUtils redisUtils; RedisUtils redisUtils;
private static final String WxAppAppId ="wx48a1b1915b10d14b";
private static final String WxAppSecret="ac4f4a9d3c97676badb70c19a2f37b16";
private static final String WxAppGrantType="authorization_code";
@Value("${minio.url.path}") @Value("${minio.url.path}")
String minioPath; String minioPath;
...@@ -127,20 +142,20 @@ public class TzsAppService { ...@@ -127,20 +142,20 @@ public class TzsAppService {
/** /**
* 产品appkey * 产品appkey
*/ */
private static final String appKey="AMOS_STUDIO"; private static final String appKey = "AMOS_STUDIO";
/** /**
* 产品product * 产品product
*/ */
private static final String product="AMOS_STUDIO_WEB"; private static final String product = "AMOS_STUDIO_WEB";
private final int successsCode = 200; private final int successsCode = 200;
public Map<String, Object> getEquipmentInfo(String record){ public Map<String, Object> getEquipmentInfo(String record) {
Map<String, Object> map = new HashMap(); Map<String, Object> map = new HashMap();
map.put("SEQUENCE_NBR",record); map.put("SEQUENCE_NBR", record);
map.put("tableName","idx_biz_view_jg_claim"); map.put("tableName", "idx_biz_view_jg_claim");
List<Map<String, Object>> detialMapList = equipmentCategoryServiceImpl.getTable(map).getRecords(); List<Map<String, Object>> detialMapList = equipmentCategoryServiceImpl.getTable(map).getRecords();
if (!ValidationUtil.isEmpty(detialMapList)){ if (!ValidationUtil.isEmpty(detialMapList)) {
map = detialMapList.iterator().next(); map = detialMapList.iterator().next();
} }
map.putAll(getQRCode(record)); map.putAll(getQRCode(record));
...@@ -149,89 +164,89 @@ public class TzsAppService { ...@@ -149,89 +164,89 @@ public class TzsAppService {
// 出厂 // 出厂
JSONObject exFactoryJsonObject = new JSONObject(); JSONObject exFactoryJsonObject = new JSONObject();
List exFactoryList = new ArrayList(); List exFactoryList = new ArrayList();
getGroupList(record, DesignInfo.class,DesignInfoModel.class, designInfoService, exFactoryList,false); getGroupList(record, DesignInfo.class, DesignInfoModel.class, designInfoService, exFactoryList, false);
getGroupList(record, ProduceInfo.class,ProduceInfoModel.class, produceInfoService, exFactoryList,false); getGroupList(record, ProduceInfo.class, ProduceInfoModel.class, produceInfoService, exFactoryList, false);
exFactoryJsonObject.put("title","出厂"); exFactoryJsonObject.put("title", "出厂");
exFactoryJsonObject.put("tabValue",exFactoryList); exFactoryJsonObject.put("tabValue", exFactoryList);
jsonArray.add(exFactoryJsonObject); jsonArray.add(exFactoryJsonObject);
// 施工 // 施工
JSONObject constructionJsonObject = new JSONObject(); JSONObject constructionJsonObject = new JSONObject();
List constructionList = new ArrayList(); List constructionList = new ArrayList();
getGroupList(record, ConstructionInfo.class, ConstructionInfoModel.class, constructionInfoService, constructionList,true); getGroupList(record, ConstructionInfo.class, ConstructionInfoModel.class, constructionInfoService, constructionList, true);
constructionJsonObject.put("title","施工"); constructionJsonObject.put("title", "施工");
constructionJsonObject.put("tabValue",constructionList); constructionJsonObject.put("tabValue", constructionList);
jsonArray.add(constructionJsonObject); jsonArray.add(constructionJsonObject);
// 注册 // 注册
JSONObject registrationJsonObject = new JSONObject(); JSONObject registrationJsonObject = new JSONObject();
List registrationList = new ArrayList(); List registrationList = new ArrayList();
getGroupList(record, RegistrationInfo.class, RegistrationInfoModel.class, registrationInfoService, registrationList,false); getGroupList(record, RegistrationInfo.class, RegistrationInfoModel.class, registrationInfoService, registrationList, false);
getGroupList(record, EquipTechParamBoiler.class, EquipTechParamBoilerModel.class, boilerService, registrationList,false); getGroupList(record, EquipTechParamBoiler.class, EquipTechParamBoilerModel.class, boilerService, registrationList, false);
getGroupList(record, EquipTechParamElevator.class, EquipTechParamElevatorModel.class, elevatorService, registrationList,false); getGroupList(record, EquipTechParamElevator.class, EquipTechParamElevatorModel.class, elevatorService, registrationList, false);
getGroupList(record, EquipTechParamLifting.class, EquipTechParamLiftingModel.class, elevatorService, registrationList,false); getGroupList(record, EquipTechParamLifting.class, EquipTechParamLiftingModel.class, elevatorService, registrationList, false);
getGroupList(record, EquipTechParamPipeline.class, EquipTechParamPipelineModel.class, pipelineService, registrationList,false); getGroupList(record, EquipTechParamPipeline.class, EquipTechParamPipelineModel.class, pipelineService, registrationList, false);
getGroupList(record, EquipTechParamRides.class, EquipTechParamRidesModel.class, ridesService, registrationList,false); getGroupList(record, EquipTechParamRides.class, EquipTechParamRidesModel.class, ridesService, registrationList, false);
getGroupList(record, EquipTechParamRopeway.class, EquipTechParamRopewayModel.class, ropewayService, registrationList,false); getGroupList(record, EquipTechParamRopeway.class, EquipTechParamRopewayModel.class, ropewayService, registrationList, false);
getGroupList(record, EquipTechParamVehicle.class, EquipTechParamVehicleModel.class, vehicleService, registrationList,false); getGroupList(record, EquipTechParamVehicle.class, EquipTechParamVehicleModel.class, vehicleService, registrationList, false);
getGroupList(record, EquipTechParamVessel.class, EquipTechParamVesselModel.class, vesselService, registrationList,false); getGroupList(record, EquipTechParamVessel.class, EquipTechParamVesselModel.class, vesselService, registrationList, false);
getGroupList(record, MainParts.class, MainPartsModel.class, mainPartsService, registrationList,false); getGroupList(record, MainParts.class, MainPartsModel.class, mainPartsService, registrationList, false);
getGroupList(record, ProtectionDevices.class, ProtectionDevicesModel.class, protectionDevicesService, registrationList,false); getGroupList(record, ProtectionDevices.class, ProtectionDevicesModel.class, protectionDevicesService, registrationList, false);
registrationJsonObject.put("title","注册"); registrationJsonObject.put("title", "注册");
registrationJsonObject.put("tabValue",registrationList); registrationJsonObject.put("tabValue", registrationList);
jsonArray.add(registrationJsonObject); jsonArray.add(registrationJsonObject);
// 使用 // 使用
JSONObject useJsonObject = new JSONObject(); JSONObject useJsonObject = new JSONObject();
List useList = new ArrayList(); List useList = new ArrayList();
getGroupList(record, UseInfo.class, UseInfoModel.class, unseInfoService, useList,false); getGroupList(record, UseInfo.class, UseInfoModel.class, unseInfoService, useList, false);
useJsonObject.put("title","使用"); useJsonObject.put("title", "使用");
useJsonObject.put("tabValue",useList); useJsonObject.put("tabValue", useList);
jsonArray.add(useJsonObject); jsonArray.add(useJsonObject);
// 维保 // 维保
JSONObject maintenanceJsonObject = new JSONObject(); JSONObject maintenanceJsonObject = new JSONObject();
List maintenanceList = new ArrayList(); List maintenanceList = new ArrayList();
getGroupList(record, MaintenanceInfo.class, MaintenanceInfoModel.class, maintenanceInfoService, maintenanceList,true); getGroupList(record, MaintenanceInfo.class, MaintenanceInfoModel.class, maintenanceInfoService, maintenanceList, true);
maintenanceJsonObject.put("title","维保"); maintenanceJsonObject.put("title", "维保");
maintenanceJsonObject.put("tabValue",maintenanceList); maintenanceJsonObject.put("tabValue", maintenanceList);
jsonArray.add(maintenanceJsonObject); jsonArray.add(maintenanceJsonObject);
// 检验 // 检验
JSONObject inspectionJsonObject = new JSONObject(); JSONObject inspectionJsonObject = new JSONObject();
List inspectionList = new ArrayList(); List inspectionList = new ArrayList();
getGroupList(record, InspectionDetectionInfo.class, InspectionDetectionInfoModel.class, inspectionDetectionInfoService, inspectionList,true); getGroupList(record, InspectionDetectionInfo.class, InspectionDetectionInfoModel.class, inspectionDetectionInfoService, inspectionList, true);
inspectionJsonObject.put("title","检验"); inspectionJsonObject.put("title", "检验");
inspectionJsonObject.put("tabValue",inspectionList); inspectionJsonObject.put("tabValue", inspectionList);
jsonArray.add(inspectionJsonObject); jsonArray.add(inspectionJsonObject);
// 其他 // 其他
JSONObject otherJsonObject = new JSONObject(); JSONObject otherJsonObject = new JSONObject();
List otherList = new ArrayList(); List otherList = new ArrayList();
getGroupList(record, OtherInfo.class, OtherInfoModel.class, otherInfoService, otherList,false); getGroupList(record, OtherInfo.class, OtherInfoModel.class, otherInfoService, otherList, false);
otherJsonObject.put("title","其他"); otherJsonObject.put("title", "其他");
otherJsonObject.put("tabValue",otherList); otherJsonObject.put("tabValue", otherList);
jsonArray.add(otherJsonObject); jsonArray.add(otherJsonObject);
map.put("tab",jsonArray); map.put("tab", jsonArray);
return map; return map;
} }
public void getGroupList(String record,Class entity, Class dto, BaseService service, List list, boolean isOne){ public void getGroupList(String record, Class entity, Class dto, BaseService service, List list, boolean isOne) {
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), entity); TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), entity);
QueryWrapper wrapper = new QueryWrapper(); QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("RECORD",record); wrapper.eq("RECORD", record);
if(isOne){ if (isOne) {
wrapper.orderByDesc("REC_DATE"); wrapper.orderByDesc("REC_DATE");
} }
List entityList = service.list(wrapper); List entityList = service.list(wrapper);
Iterator iterator = entityList.iterator(); Iterator iterator = entityList.iterator();
if(!isOne) { if (!isOne) {
if (!ValidationUtil.isEmpty(entityList)) { if (!ValidationUtil.isEmpty(entityList)) {
while (iterator.hasNext()) { while (iterator.hasNext()) {
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(iterator.next())); JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(iterator.next()));
JSONObject result = getFieldList(dto, jsonObject,null); JSONObject result = getFieldList(dto, jsonObject, null);
list.add(result); list.add(result);
} }
} }
...@@ -239,56 +254,56 @@ public class TzsAppService { ...@@ -239,56 +254,56 @@ public class TzsAppService {
} else { } else {
int count = entityList.size(); int count = entityList.size();
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(iterator.next())); JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(iterator.next()));
JSONObject result = getFieldList(dto, jsonObject,count); JSONObject result = getFieldList(dto, jsonObject, count);
list.add(result); list.add(result);
} }
} }
public JSONObject getFieldList(Class clazz,JSONObject jsonObject,Integer count){ public JSONObject getFieldList(Class clazz, JSONObject jsonObject, Integer count) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
JSONObject ApiModel = JSON.parseObject(JSON.toJSONString(clazz.getAnnotation(ApiModel.class))); JSONObject ApiModel = JSON.parseObject(JSON.toJSONString(clazz.getAnnotation(ApiModel.class)));
String groupName = ApiModel.getString("description"); String groupName = ApiModel.getString("description");
Field[] declaredFields = clazz.getDeclaredFields(); Field[] declaredFields = clazz.getDeclaredFields();
List<Map<String,Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
if(!ValidationUtil.isEmpty(declaredFields)){ if (!ValidationUtil.isEmpty(declaredFields)) {
for (Field field : declaredFields) { for (Field field : declaredFields) {
if (field.getAnnotation(ApiModelProperty.class) != null && !ValidationUtil.isEmpty(field.getAnnotation(ApiModelProperty.class).value())) { if (field.getAnnotation(ApiModelProperty.class) != null && !ValidationUtil.isEmpty(field.getAnnotation(ApiModelProperty.class).value())) {
Map<String,Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
String filedName = field.getAnnotation(ApiModelProperty.class).value(); String filedName = field.getAnnotation(ApiModelProperty.class).value();
// key和value可根据需求存 // key和value可根据需求存
// 这存的key为注解的值,value为类属性名 // 这存的key为注解的值,value为类属性名
map.put( "fieldName",filedName); map.put("fieldName", filedName);
map.put("fieldValue",jsonObject.getString(field.getName())); map.put("fieldValue", jsonObject.getString(field.getName()));
map.put("fieldKey",field.getName()); map.put("fieldKey", field.getName());
list.add(map); list.add(map);
} }
} }
} }
// 整理出现多个附件的情况 // 整理出现多个附件的情况
Iterator<Map<String,Object>> iterator = list.iterator(); Iterator<Map<String, Object>> iterator = list.iterator();
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
Boolean bool = true; Boolean bool = true;
String name = ""; String name = "";
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map<String,Object> map = iterator.next(); Map<String, Object> map = iterator.next();
String fieldName = map.get("fieldName").toString(); String fieldName = map.get("fieldName").toString();
if(fieldName.contains("附件")){ if (fieldName.contains("附件")) {
if(bool){ if (bool) {
// 第一个出现的附件名称为表单显示的名称 // 第一个出现的附件名称为表单显示的名称
name = fieldName; name = fieldName;
bool = false; bool = false;
} }
if(!ValidationUtil.isEmpty(map.get("fieldValue"))){ if (!ValidationUtil.isEmpty(map.get("fieldValue"))) {
JSONArray jsonArray = JSON.parseArray(String.valueOf(map.get("fieldValue"))); JSONArray jsonArray = JSON.parseArray(String.valueOf(map.get("fieldValue")));
JSONArray json = new JSONArray(); JSONArray json = new JSONArray();
for(Object obj: jsonArray){ for (Object obj : jsonArray) {
JSONObject object = JSON.parseObject(JSON.toJSONString(obj)); JSONObject object = JSON.parseObject(JSON.toJSONString(obj));
if(!ValidationUtil.isEmpty(object)){ if (!ValidationUtil.isEmpty(object)) {
object.getString("url"); object.getString("url");
object.put("url",minioPath+object.getString("url")); object.put("url", minioPath + object.getString("url"));
json.add(object); json.add(object);
} }
} }
...@@ -299,7 +314,7 @@ public class TzsAppService { ...@@ -299,7 +314,7 @@ public class TzsAppService {
} }
} }
// 如果有附件 整理为一个附件 添加入list里 // 如果有附件 整理为一个附件 添加入list里
if(!bool) { if (!bool) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("fieldKey", "files"); map.put("fieldKey", "files");
map.put("fieldValue", array); map.put("fieldValue", array);
...@@ -307,33 +322,34 @@ public class TzsAppService { ...@@ -307,33 +322,34 @@ public class TzsAppService {
list.add(map); list.add(map);
} }
if(!ValidationUtil.isEmpty(count)){ if (!ValidationUtil.isEmpty(count)) {
result.put("groupCount",count); result.put("groupCount", count);
} }
result.put("groupName",ApiModel.getString("description")); result.put("groupName", ApiModel.getString("description"));
result.put("groupKey",ApiModel.getString("value")); result.put("groupKey", ApiModel.getString("value"));
result.put("groupValue",list); result.put("groupValue", list);
return result; return result;
} }
/** /**
* 获取焊口编号 * 获取焊口编号
*
* @return * @return
*/ */
public JSONObject getQRCode(String code){ public JSONObject getQRCode(String code) {
String url = ""; String url = "";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
byte[] bytes = QRCodeUtil.generateQRCodeImageByteData(code,50); byte[] bytes = QRCodeUtil.generateQRCodeImageByteData(code, 50);
InputStream inputStream = new ByteArrayInputStream(bytes); InputStream inputStream = new ByteArrayInputStream(bytes);
try { try {
MultipartFile file = new MockMultipartFile(code+".jpg",code+".jpg", ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream); MultipartFile file = new MockMultipartFile(code + ".jpg", code + ".jpg", ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
FeignClientResult<Map<String, String>> date = Systemctl.fileStorageClient.updateCommonFileFree(file, "ugp/qrcode"); FeignClientResult<Map<String, String>> date = Systemctl.fileStorageClient.updateCommonFileFree(file, "ugp/qrcode");
if (date != null) { if (date != null) {
Map<String, String> map = date.getResult(); Map<String, String> map = date.getResult();
Iterator<String> it = map.keySet().iterator(); Iterator<String> it = map.keySet().iterator();
String urlString=it.next(); String urlString = it.next();
jsonObject.put("fileUrl", minioPath+urlString); jsonObject.put("fileUrl", minioPath + urlString);
jsonObject.put("fileName", code); jsonObject.put("fileName", code);
} }
} catch (IOException e) { } catch (IOException e) {
...@@ -347,8 +363,8 @@ public class TzsAppService { ...@@ -347,8 +363,8 @@ public class TzsAppService {
return ObjectUtils.isEmpty(categoryOtherInfo) ? null : getEquipmentInfo(categoryOtherInfo.getRecord()); return ObjectUtils.isEmpty(categoryOtherInfo) ? null : getEquipmentInfo(categoryOtherInfo.getRecord());
} }
public Map<String, Object> login(MobileLoginParam param){ public Map<String, Object> login(MobileLoginParam param) {
Map<String, Object> result = new LinkedHashMap<>(); Map<String, Object> result = new LinkedHashMap<>();
IdPasswordAuthModel idPasswordAuthModel = new IdPasswordAuthModel(); IdPasswordAuthModel idPasswordAuthModel = new IdPasswordAuthModel();
idPasswordAuthModel.setLoginId(param.getPhoneNo()); idPasswordAuthModel.setLoginId(param.getPhoneNo());
...@@ -358,7 +374,7 @@ public class TzsAppService { ...@@ -358,7 +374,7 @@ public class TzsAppService {
RequestContext.setProduct(product); RequestContext.setProduct(product);
RequestContext.setAppKey(appKey); RequestContext.setAppKey(appKey);
try { try {
idpassword = Privilege.authClient.idpassword(idPasswordAuthModel); idpassword = Privilege.authClient.idpassword(idPasswordAuthModel);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -393,42 +409,53 @@ public class TzsAppService { ...@@ -393,42 +409,53 @@ public class TzsAppService {
} }
@SneakyThrows
public JSONObject wxUserLogin(JSONObject wx) { public JSONObject wxUserLogin(JSONObject wx) {
/* if (redisUtils.hasKey(WXUSER_TOKEN)) {
Object obj= redisUtils.get(WXUSER_TOKEN); JSONObject obj = getSessionKey(wx);
return JSONObject.parseObject(obj.toString()); String sessionKey = obj.getString("session_key");
}else { //被加密的数据
StringBuffer buffer= new StringBuffer("https://api.weixin.qq.com/sns/jscode2session?appid=") byte[] dataByte = Base64.getDecoder().decode(wx.getString("encryptedData"));
.append(wx.getString("appid")).append("&secret=").append(wx.getString("secret")).append("&js_code=").append(wx.getString("js_code")) //加密秘钥
.append("&grant_type=").append( wx.getString("grant_type")); byte[] keyByte = Base64.getDecoder().decode(sessionKey);
String responseStr = HttpUtils.doGet(buffer.toString()); //偏移量
JSONObject response = null; byte[] ivByte = Base64.getDecoder().decode(wx.getString("iv"));
try { JSONObject res=null;
response = JSONObject.parseObject(responseStr); // 如果密钥不足16位,那么就补足. 这个if 中的内容很重要
int base = 16;
System.out.println("666"+response.getString("session_key")); if (keyByte.length % base != 0) {
} catch (Exception e) { int groups = keyByte.length / base + (keyByte.length % base != 0 ? 1 : 0);
throw new BadRequest("session_key 出错:" + e.getMessage()); byte[] temp = new byte[groups * base];
Arrays.fill(temp, (byte) 0);
System.arraycopy(keyByte, 0, temp, 0, keyByte.length);
keyByte = temp;
} }
if(response.get("session_key") != null) { // 获取token 成功 // 初始化
try { Security.addProvider(new BouncyCastleProvider());
redisUtils.set(WXUSER_TOKEN, response,time); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding","BC");
return response; SecretKeySpec spec = new SecretKeySpec(keyByte, "AES");
} catch (Exception e) { AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
throw new BadRequest("session_key 出错:" + e.getMessage()); parameters.init(new IvParameterSpec(ivByte));
} cipher.init(Cipher.DECRYPT_MODE, spec, parameters);// 初始化
} else { byte[] resultByte = cipher.doFinal(dataByte);
throw new BadRequest("session_key 出错:" + response); if (null != resultByte && resultByte.length > 0) {
String result = new String(resultByte, "UTF-8");
res=JSONObject.parseObject(result);
return res ;
} }
}*/ return res;
}
StringBuffer buffer= new StringBuffer("https://api.weixin.qq.com/sns/jscode2session?appid=") private JSONObject getSessionKey(JSONObject wx) {
.append(wx.getString("appid")).append("&secret=").append(wx.getString("secret")).append("&js_code=").append(wx.getString("js_code")) StringBuffer buffer = new StringBuffer("https://api.weixin.qq.com/sns/jscode2session?appid=")
.append("&grant_type=").append( wx.getString("grant_type")); .append(WxAppAppId).append("&secret=").append(WxAppSecret).append("&js_code=").append(wx.getString("js_code"))
.append("&grant_type=").append(WxAppGrantType);
String responseStr = HttpUtils.doGet(buffer.toString()); String responseStr = HttpUtils.doGet(buffer.toString());
JSONObject response=JSONObject.parseObject(responseStr); JSONObject response = JSONObject.parseObject(responseStr);
return response; return response;
} }
} }
spring.application.name=TZS spring.application.name=TZS-cpp
server.servlet.context-path=/tzs server.servlet.context-path=/tzs
server.port=11000 server.port=11000
spring.profiles.active=dev3 spring.profiles.active=dev3
...@@ -163,4 +163,8 @@ spring.main.allow-bean-definition-overriding=true ...@@ -163,4 +163,8 @@ spring.main.allow-bean-definition-overriding=true
is.ugp=false is.ugp=false
#\u5DE5\u4F5C\u53F0\u7528\u6237\u7EDF\u4E00\u663E\u793A\u5934\u50CF #\u5DE5\u4F5C\u53F0\u7528\u6237\u7EDF\u4E00\u663E\u793A\u5934\u50CF
tzs.auth.user.photo=/public/common/userPic.png tzs.auth.user.photo=/public/common/userPic.png
\ No newline at end of file
tzs.WxApp.appId=wx48a1b1915b10d14b
tzs.WxApp.secret=ac4f4a9d3c97676badb70c19a2f37b16
tzs.WxApp.grant-type=authorization_code
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment