Commit eb80da61 authored by xianjun's avatar xianjun

修改微信小程序接口文档

parent 53e9c498
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
<module>yzg-util-db</module> <module>yzg-util-db</module>
<module>yzg-util-cloud</module> <module>yzg-util-cloud</module>
<module>yzg-util-mq</module> <module>yzg-util-mq</module>
<module>yzg-util-image</module> <!-- <module>yzg-util-image</module>-->
<!-- <module>yzg-util-image-extend</module>--> <!-- <module>yzg-util-image-extend</module>-->
<module>yzg-util-print</module> <module>yzg-util-print</module>
<module>yzg-util-chinese</module> <module>yzg-util-chinese</module>
<module>yzg-util-file</module> <!-- <module>yzg-util-file</module>-->
<module>yzg-util-redis</module> <module>yzg-util-redis</module>
<module>yzg-util-wxxcx</module> <module>yzg-util-wxxcx</module>
</modules> </modules>
......
...@@ -18,13 +18,13 @@ public class WxXcxConfig { ...@@ -18,13 +18,13 @@ public class WxXcxConfig {
private String baseUrl; private String baseUrl;
/** /**
* 公共URI * appid
*/ */
@Value("${yzg.wx.xcx.appid:wxd70bc341df16d0b8}") @Value("${yzg.wx.xcx.appid:wxd70bc341df16d0b8}")
private String appid; private String appid;
/** /**
* 公共URI * secret
*/ */
@Value("${yzg.wx.xcx.secret:a8a4bc5f1dc5cde3c9abddf107c5598e}") @Value("${yzg.wx.xcx.secret:a8a4bc5f1dc5cde3c9abddf107c5598e}")
private String secret; private String secret;
......
package com.yanzuoguang.wxxcx.base; package com.yanzuoguang.wxxcx.base;
import com.alibaba.fastjson.JSONObject;
import com.yanzuoguang.util.helper.HttpHelper; import com.yanzuoguang.util.helper.HttpHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -15,6 +18,7 @@ import java.util.Map; ...@@ -15,6 +18,7 @@ import java.util.Map;
*/ */
@Component @Component
public class WxXcxRequestImpl implements WxXcxRequest { public class WxXcxRequestImpl implements WxXcxRequest {
Logger logger = LoggerFactory.getLogger(WxXcxRequestImpl.class);
@Value("${yzg.wx.xwx.charset:utf-8}") @Value("${yzg.wx.xwx.charset:utf-8}")
private String defaultCharSet; private String defaultCharSet;
...@@ -22,7 +26,8 @@ public class WxXcxRequestImpl implements WxXcxRequest { ...@@ -22,7 +26,8 @@ public class WxXcxRequestImpl implements WxXcxRequest {
@Override @Override
public <T> T request(WxXcxRequestUrl req, WxXcxResponseConvert<T> convert) { public <T> T request(WxXcxRequestUrl req, WxXcxResponseConvert<T> convert) {
String url = req.getUrl(); String url = req.getUrl();
String charSet = defaultCharSet; // String charSet = defaultCharSet;
String charSet = "utf-8";
Map<String, String> header; Map<String, String> header;
if (req instanceof WxXcxRequestHeader) { if (req instanceof WxXcxRequestHeader) {
// 设置header信息 // 设置header信息
......
package com.yanzuoguang.wxxcx.dataanalysis.retain; package com.yanzuoguang.wxxcx.dataanalysis.retain;
import java.io.Serializable;
/** /**
* 获取用户访问小程序日留存 请求 * 获取用户访问小程序日留存 请求
* *
* @author 李贤军 * @author 李贤军
*/ */
public class WxXcxAnalysisGetDailyRetainReq { public class WxXcxAnalysisGetDailyRetainReq implements Serializable {
/** /**
* 接口调用凭证 * 接口调用凭证
*/ */
......
package com.yanzuoguang.wxxcx.dataanalysis.retain; package com.yanzuoguang.wxxcx.dataanalysis.retain;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.yanzuoguang.util.helper.HttpHelper; import com.yanzuoguang.util.helper.HttpHelper;
import com.yanzuoguang.util.helper.JsonHelper; import com.yanzuoguang.util.helper.JsonHelper;
...@@ -27,7 +28,9 @@ public class WxXcxAnalysisGetDailyRetainRequest implements WxXcxRequestUrl, WxXc ...@@ -27,7 +28,9 @@ public class WxXcxAnalysisGetDailyRetainRequest implements WxXcxRequestUrl, WxXc
@Override @Override
public String getUrl() { public String getUrl() {
return wxXcxConfig.getBaseUrl() + wxXcxConfig.getAnalysisGetDailyRetainUrl() + "?" + this.getUrlPara();
return "https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo" + "?" + this.getUrlPara();
// return wxXcxConfig.getBaseUrl() + wxXcxConfig.getAnalysisGetDailyRetainUrl() + "?" + this.getUrlPara();
} }
@Override @Override
...@@ -37,7 +40,7 @@ public class WxXcxAnalysisGetDailyRetainRequest implements WxXcxRequestUrl, WxXc ...@@ -37,7 +40,7 @@ public class WxXcxAnalysisGetDailyRetainRequest implements WxXcxRequestUrl, WxXc
@Override @Override
public String getPost() { public String getPost() {
return HttpHelper.getUrlParameter(req); return JSONObject.toJSONString(req);
} }
public WxXcxAnalysisGetDailyRetainRes getResponse() { public WxXcxAnalysisGetDailyRetainRes getResponse() {
......
package com.yanzuoguang.wxxcx.token; package com.yanzuoguang.wxxcx.token;
import java.io.Serializable;
/** /**
* 获取小程序全局唯一后台接口调用凭据 请求 * 获取小程序全局唯一后台接口调用凭据 请求
* *
* @author 李贤军 * @author 李贤军
*/ */
public class WxXcxAuthGetAccessTokenReq { public class WxXcxAuthGetAccessTokenReq implements Serializable {
/** /**
* 填写 client_credential * 填写 client_credential
*/ */
......
...@@ -24,7 +24,8 @@ public class WxXcxAuthGetAccessTokenRequest implements WxXcxRequestUrl, WxXcxReq ...@@ -24,7 +24,8 @@ public class WxXcxAuthGetAccessTokenRequest implements WxXcxRequestUrl, WxXcxReq
@Override @Override
public String getUrl() { public String getUrl() {
return wxXcxConfig.getBaseUrl() + wxXcxConfig.getAuthGetAccessTokenUrl() + "?" + this.getUrlPara(); return "https://api.weixin.qq.com/cgi-bin/token"+ "?" + this.getUrlPara();
// return wxXcxConfig.getBaseUrl() + wxXcxConfig.getAuthGetAccessTokenUrl() + "?" + this.getUrlPara();
} }
@Override @Override
......
...@@ -2,12 +2,14 @@ package com.yanzuoguang.wxxcx.token; ...@@ -2,12 +2,14 @@ package com.yanzuoguang.wxxcx.token;
import com.yanzuoguang.wxxcx.base.WxXcxResponseBaseError; import com.yanzuoguang.wxxcx.base.WxXcxResponseBaseError;
import java.io.Serializable;
/** /**
* 获取小程序全局唯一后台接口调用凭据 响应 * 获取小程序全局唯一后台接口调用凭据 响应
* *
* @author 李贤军 * @author 李贤军
*/ */
public class WxXcxAuthGetAccessTokenRes extends WxXcxResponseBaseError { public class WxXcxAuthGetAccessTokenRes extends WxXcxResponseBaseError implements Serializable {
/** /**
* access_token * access_token
*/ */
......
package com.yanzuoguang.wxxcx.user.getphone; package com.yanzuoguang.wxxcx.user.getphone;
import java.io.Serializable;
/** /**
* 获取手机号 请求 * 获取手机号 请求
* *
* @author 李贤军 * @author 李贤军
*/ */
public class WxXcxGetPhoneNumberReq { public class WxXcxGetPhoneNumberReq implements Serializable {
/** /**
* 接口调用凭证 * 接口调用凭证
*/ */
......
...@@ -26,7 +26,8 @@ public class WxXcxGetPhoneNumberRequest implements WxXcxRequestUrl, WxXcxRequest ...@@ -26,7 +26,8 @@ public class WxXcxGetPhoneNumberRequest implements WxXcxRequestUrl, WxXcxRequest
@Override @Override
public String getUrl() { public String getUrl() {
return wxXcxConfig.getBaseUrl() + wxXcxConfig.getGetPhoneNumberUrl() + "?" + this.getUrlPara(); return "https://api.weixin.qq.com/wxa/business/getuserphonenumber" + "?" + this.getUrlPara();
// return wxXcxConfig.getBaseUrl() + wxXcxConfig.getGetPhoneNumberUrl() + "?" + this.getUrlPara();
} }
@Override @Override
...@@ -36,7 +37,7 @@ public class WxXcxGetPhoneNumberRequest implements WxXcxRequestUrl, WxXcxRequest ...@@ -36,7 +37,7 @@ public class WxXcxGetPhoneNumberRequest implements WxXcxRequestUrl, WxXcxRequest
@Override @Override
public String getPost() { public String getPost() {
return HttpHelper.getUrlParameter(req); return JsonHelper.serialize(req);
} }
public WxXcxGetPhoneNumberRes getResponse() { public WxXcxGetPhoneNumberRes getResponse() {
......
...@@ -2,12 +2,14 @@ package com.yanzuoguang.wxxcx.user.getphone; ...@@ -2,12 +2,14 @@ package com.yanzuoguang.wxxcx.user.getphone;
import com.yanzuoguang.wxxcx.base.WxXcxResponseBaseError; import com.yanzuoguang.wxxcx.base.WxXcxResponseBaseError;
import java.io.Serializable;
/** /**
* 获取手机号 响应 * 获取手机号 响应
* *
* @author 李贤军 * @author 李贤军
*/ */
public class WxXcxGetPhoneNumberRes extends WxXcxResponseBaseError { public class WxXcxGetPhoneNumberRes extends WxXcxResponseBaseError implements Serializable {
/** /**
* 用户手机号信息 * 用户手机号信息
*/ */
......
package com.yanzuoguang.wxxcx.login; package com.yanzuoguang.wxxcx.login;
import com.alibaba.fastjson.JSONObject;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.yanzuoguang.wxxcx.base.WxXcxAccessToken;
import com.yanzuoguang.wxxcx.base.WxXcxConfig;
import com.yanzuoguang.wxxcx.base.WxXcxRequest;
import com.yanzuoguang.wxxcx.base.WxXcxRequestImpl;
import com.yanzuoguang.wxxcx.dataanalysis.retain.WxXcxAnalysisGetDailyRetainReq;
import com.yanzuoguang.wxxcx.dataanalysis.retain.service.WxXcxAnalysisGetDailyRetainService;
import com.yanzuoguang.wxxcx.dataanalysis.retain.service.impl.WxXcxAnalysisGetDailyRetainServiceImpl;
import com.yanzuoguang.wxxcx.token.WxXcxAuthGetAccessTokenReq;
import com.yanzuoguang.wxxcx.token.service.WxXcxAuthGetAccessTokenService;
import com.yanzuoguang.wxxcx.token.service.impl.WxXcxAuthGetAccessTokenServiceImpl;
import com.yanzuoguang.wxxcx.user.getphone.WxXcxGetPhoneNumberReq;
import com.yanzuoguang.wxxcx.user.getphone.service.WxXcxGetPhoneNumberService;
import com.yanzuoguang.wxxcx.user.getphone.service.impl.WxXcxGetPhoneNumberServiceImpl;
import org.junit.Test; import org.junit.Test;
/** /**
...@@ -7,8 +22,40 @@ import org.junit.Test; ...@@ -7,8 +22,40 @@ import org.junit.Test;
*/ */
public class WxXcxAuthCode2SessionTest { public class WxXcxAuthCode2SessionTest {
@Test @Test
public void wxXcxAuthCode2Session() { public void wxXcxAuthCode2Session() {
WxXcxConfig wxXcxConfig = new WxXcxConfig();
WxXcxRequest wxXcxRequest = new WxXcxRequestImpl();
WxXcxAuthGetAccessTokenService WxXcxAuthGetAccessTokenService = new WxXcxAuthGetAccessTokenServiceImpl(wxXcxConfig,wxXcxRequest);
WxXcxAuthGetAccessTokenReq req = new WxXcxAuthGetAccessTokenReq();
req.setAppid("wxd70bc341df16d0b8");
req.setSecret("a8a4bc5f1dc5cde3c9abddf107c5598e");
req.setGrant_type("client_credential");
System.out.println(WxXcxAuthGetAccessTokenService.getAuthGetAccessToken(req).getAccess_token());
}
@Test
public void getPhoneNumber() {
WxXcxConfig wxXcxConfig = new WxXcxConfig();
WxXcxRequest wxXcxRequest = new WxXcxRequestImpl();
WxXcxAccessToken wxXcxAccessToken = new WxXcxAccessToken();
WxXcxAuthGetAccessTokenService wxXcxAuthGetAccessTokenService = new WxXcxAuthGetAccessTokenServiceImpl(wxXcxConfig,wxXcxRequest);
WxXcxAuthGetAccessTokenReq req = new WxXcxAuthGetAccessTokenReq();
req.setAppid("wxd70bc341df16d0b8");
req.setSecret("a8a4bc5f1dc5cde3c9abddf107c5598e");
req.setGrant_type("client_credential");
String token = wxXcxAuthGetAccessTokenService.getAuthGetAccessToken(req).getAccess_token();
System.out.println(token);
wxXcxAccessToken.setAccess_token(token);
WxXcxAnalysisGetDailyRetainService wxXcxAnalysisGetDailyRetainService = new WxXcxAnalysisGetDailyRetainServiceImpl(wxXcxConfig,wxXcxRequest);
WxXcxAnalysisGetDailyRetainReq retainReq = new WxXcxAnalysisGetDailyRetainReq();
retainReq.setAccess_token(token);
retainReq.setBegin_date("20220707");
retainReq.setEnd_date("20220707");
System.out.println(JSONObject.toJSONString(wxXcxAnalysisGetDailyRetainService.getAnalysisGetDailyRetain(wxXcxAccessToken,retainReq)));
} }
} }
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