|
|
@ -1,10 +1,8 @@ |
|
|
|
package com.ccsens.util.wx; |
|
|
|
|
|
|
|
import cn.hutool.core.lang.Console; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.URLUtil; |
|
|
|
import cn.hutool.http.HttpRequest; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONException; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.util.DateUtil; |
|
|
@ -16,7 +14,7 @@ import com.ccsens.util.exception.BaseException; |
|
|
|
import com.ccsens.util.exception.BusinessException; |
|
|
|
import com.ccsens.util.exception.WxException; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
@ -31,6 +29,7 @@ import java.util.Map; |
|
|
|
/** |
|
|
|
* @author __zHangSan |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
public class WxGzhUtil { |
|
|
|
|
|
|
@ -201,7 +200,7 @@ public class WxGzhUtil { |
|
|
|
String[] tmpArr = { TOKEN, timestamp, nonce }; |
|
|
|
Arrays.sort(tmpArr); |
|
|
|
String sign = sha1Encode( arrayToString(tmpArr)); |
|
|
|
Console.log("sign:{} , signature: {}",sign,signature); |
|
|
|
log.info("sign:{} , signature: {}",sign,signature); |
|
|
|
if (sign.equalsIgnoreCase(signature)) { |
|
|
|
return true; |
|
|
|
} |
|
|
@ -217,7 +216,7 @@ public class WxGzhUtil { |
|
|
|
WxAccessToken wxAccessToken = null; |
|
|
|
String url = String.format(URL_GET_ACCESS_TOKEN,"client_credential",appid_health,secret_health); |
|
|
|
String response = HttpRequest.get(url).execute().body(); |
|
|
|
Console.log("getAccessToken: {}",response); |
|
|
|
log.info("getAccessToken: {}",response); |
|
|
|
try { |
|
|
|
if(StrUtil.isEmpty(response) || null == (wxAccessToken = JacksonUtil.jsonToBean(response, WxAccessToken.class))) { |
|
|
|
throw new BusinessException(-1,"the response of HttpRequest is empty."); |
|
|
@ -246,7 +245,7 @@ public class WxGzhUtil { |
|
|
|
public static String queryMenu() throws BaseException { |
|
|
|
String url = String.format(URL_QUERY_MENU,getAccessToken()); |
|
|
|
String menuString = HttpRequest.get(url).execute().body(); |
|
|
|
Console.log("url:{}, menuString: {}",url,menuString); |
|
|
|
log.info("url:{}, menuString: {}",url,menuString); |
|
|
|
return menuString; |
|
|
|
} |
|
|
|
|
|
|
@ -258,7 +257,7 @@ public class WxGzhUtil { |
|
|
|
String menuString = null; |
|
|
|
try { |
|
|
|
menuString = JacksonUtil.beanToJson(gzhMenu); |
|
|
|
Console.log(menuString); |
|
|
|
log.info(menuString); |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
throw new BusinessException(-1,e.getMessage()); |
|
|
@ -293,7 +292,7 @@ public class WxGzhUtil { |
|
|
|
WxOauth2AccessToken wxOauth2AccessToken = null; |
|
|
|
String url = String.format(URL_GET_OAUTH2_ACCESS_TOKEN,appId(identifyType),secret(identifyType),code); |
|
|
|
String response = HttpRequest.get(url).execute().body(); |
|
|
|
Console.log("url: {}\nresponse: {}",url,response); |
|
|
|
log.info("url: {}\nresponse: {}",url,response); |
|
|
|
try { |
|
|
|
if(StrUtil.isEmpty(response) || null == (wxOauth2AccessToken = JacksonUtil.jsonToBean(response,WxOauth2AccessToken.class))) { |
|
|
|
throw new BusinessException(-1,"the response of HttpRequest is empty."); |
|
|
@ -323,7 +322,7 @@ public class WxGzhUtil { |
|
|
|
WxOauth2UserInfo wxOauth2UserInfo = null; |
|
|
|
String url = String.format(URL_GET_OAUTH2_USERINFO,accessToken,openId); |
|
|
|
String response = HttpRequest.get(url).execute().body(); |
|
|
|
Console.log("url: {}\nresponse: {}",url,response); |
|
|
|
log.info("url: {}\nresponse: {}",url,response); |
|
|
|
try { |
|
|
|
if(StrUtil.isEmpty(response) || null == (wxOauth2UserInfo = JacksonUtil.jsonToBean(response,WxOauth2UserInfo.class))) { |
|
|
|
throw new BusinessException(-1,"the response of HttpRequest is empty."); |
|
|
@ -363,7 +362,7 @@ public class WxGzhUtil { |
|
|
|
* @param response |
|
|
|
*/ |
|
|
|
public static void pageResponseSuccess(String response) { |
|
|
|
Console.log("返回结果:{}", response); |
|
|
|
log.info("返回结果:{}", response); |
|
|
|
JSONObject result; |
|
|
|
try { |
|
|
|
if(StrUtil.isEmpty(response) || null == (result = JSONObject.parseObject(response))) { |
|
|
|