parent
6039958843
commit
497a7a30af
@ -0,0 +1,92 @@ |
||||
package com.v1.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
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.WxUtils; |
||||
import com.hai.model.ResponseData; |
||||
import com.v1.config.SysConst; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import me.chanjar.weixin.common.util.crypto.SHA1; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
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.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author sum1dream |
||||
*/ |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/wxMsg") |
||||
@Api(value = "自建站接口") |
||||
public class WxMsgController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ThirdPartyController.class); |
||||
|
||||
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "验证servlet") |
||||
public String verifyWxToken(HttpServletRequest request) { |
||||
|
||||
try { |
||||
log.info("进入验证servlet!!!!!"); |
||||
log.info(String.valueOf(request)); |
||||
String msgSignature = request.getParameter("signature"); |
||||
String msgTimestamp = request.getParameter("timestamp"); |
||||
String msgNonce = request.getParameter("nonce"); |
||||
String echoStr = request.getParameter("echoStr"); |
||||
|
||||
|
||||
Map<String, Object> params = new HashMap<>(); |
||||
params.put("timestamp", msgTimestamp); |
||||
params.put("nonce", msgNonce); |
||||
String signatureStr = WxUtils.generateSignature(params); |
||||
String sign = SHA1.gen(signatureStr); |
||||
|
||||
if (msgSignature.equals(sign)) { |
||||
log.info("验证通过!!!!!"); |
||||
return echoStr; |
||||
} |
||||
log.info("验证失败!!!!!"); |
||||
return null; |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
|
||||
@RequestMapping(value = "/getWxToken", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "获取微信token") |
||||
public ResponseData getWxToken() { |
||||
try { |
||||
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失败"); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(accessTokenObject); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,2 @@ |
||||
wxH5AppId=wxb05f4cb44994a960 |
||||
wxH5AppSecret=68b540ebce7a4020420f4e5997b1531b |
Loading…
Reference in new issue