|
|
@ -1,6 +1,13 @@ |
|
|
|
package com.cweb.controller; |
|
|
|
package com.cweb.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
|
|
import com.cweb.config.SysConst; |
|
|
|
|
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
|
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
|
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
|
|
|
|
import com.hai.common.utils.HttpsUtils; |
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
|
|
|
|
import com.hai.common.utils.WxUtils; |
|
|
|
import com.hai.entity.BsCompany; |
|
|
|
import com.hai.entity.BsCompany; |
|
|
|
import com.hai.entity.SecConfig; |
|
|
|
import com.hai.entity.SecConfig; |
|
|
|
import com.hai.entity.SecRegion; |
|
|
|
import com.hai.entity.SecRegion; |
|
|
@ -10,6 +17,7 @@ import com.hai.service.CommonService; |
|
|
|
import com.hai.service.SecConfigService; |
|
|
|
import com.hai.service.SecConfigService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
|
|
|
import me.chanjar.weixin.common.util.crypto.SHA1; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -223,4 +231,51 @@ public class CommonController { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getScanCodePageHtmlSign", method = RequestMethod.POST) |
|
|
|
|
|
|
|
@ResponseBody |
|
|
|
|
|
|
|
@ApiOperation(value = "获取扫码页面签名") |
|
|
|
|
|
|
|
public ResponseData getScanCodePageHtmlSign(@RequestBody JSONObject body) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (body == null || StringUtils.isBlank(body.getString("url"))) { |
|
|
|
|
|
|
|
log.error("getH5UserInfo error!", "参数校验失败" ); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
|
|
|
|
params.put("appid", SysConst.getSysConfig().getWxH5AppId()); |
|
|
|
|
|
|
|
params.put("secret", SysConst.getSysConfig().getWxH5AppSecret()); |
|
|
|
|
|
|
|
params.put("grant_type", "client_credential"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject accessTokenObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", params); |
|
|
|
|
|
|
|
if (accessTokenObject == null) { |
|
|
|
|
|
|
|
log.error("getH5UserInfo error!", "获取微信access_token失败" ); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取微信access_token失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params.clear(); |
|
|
|
|
|
|
|
params.put("access_token", accessTokenObject.getString("access_token")); |
|
|
|
|
|
|
|
params.put("type", "jsapi"); |
|
|
|
|
|
|
|
JSONObject jsapiTicketObject = HttpsUtils.doGet("https://api.weixin.qq.com/cgi-bin/ticket/getticket", params); |
|
|
|
|
|
|
|
if (jsapiTicketObject == null) { |
|
|
|
|
|
|
|
log.error("getH5UserInfo error!", "获取微信jsapi_ticket失败" ); |
|
|
|
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取微信jsapi_ticket失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params = new HashMap<>(); |
|
|
|
|
|
|
|
params.put("noncestr", WxUtils.makeNonStr()); |
|
|
|
|
|
|
|
params.put("jsapi_ticket", jsapiTicketObject.getString("ticket")); |
|
|
|
|
|
|
|
params.put("timestamp", System.currentTimeMillis() / 1000); |
|
|
|
|
|
|
|
params.put("url", body.getString("url")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String signatureStr = WxUtils.generateSignature(params); |
|
|
|
|
|
|
|
System.out.println(signatureStr); |
|
|
|
|
|
|
|
params.put("signature", SHA1.gen(signatureStr)); |
|
|
|
|
|
|
|
return ResponseMsgUtil.success(params); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|