mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
新增 微信第三方平台 设置小程序用户隐私保护指引 接口
This commit is contained in:
@@ -278,4 +278,24 @@ public class AgentDevController extends BaseController {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置小程序用户隐私保护指引
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/setPrivacySetting")
|
||||
public RestApiResponse<?> setPrivacySetting (@RequestBody PrivacySettingDTO dto) {
|
||||
logger.info("设置小程序用户隐私保护指引 params:{}", JSONObject.toJSONString(dto));
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
String result = agentDevService.setPrivacySetting(dto);
|
||||
response = new RestApiResponse<>(result);
|
||||
} catch (Exception e) {
|
||||
logger.info("设置小程序用户隐私保护指引 error, ", e);
|
||||
response = new RestApiResponse<>(e);
|
||||
}
|
||||
logger.info("设置小程序用户隐私保护指引 result:{}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.jsowell.common.util.wxplatform.WXBizMsgCrypt;
|
||||
import com.jsowell.common.util.wxplatform.WXXmlToMapUtil;
|
||||
import com.jsowell.pile.domain.agentDev.AuditItem;
|
||||
import com.jsowell.pile.domain.agentDev.CategoryInfo;
|
||||
import com.jsowell.pile.domain.agentDev.UserInfoSetting;
|
||||
import com.jsowell.pile.dto.agentDev.*;
|
||||
import com.jsowell.pile.vo.agentDev.AuthInfoVO;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
@@ -265,7 +266,7 @@ public class AgentDevService {
|
||||
* @param authAppId
|
||||
* @return
|
||||
*/
|
||||
public String getAuthAccessToken(String authAppId) {
|
||||
private String getAuthAccessToken(String authAppId) {
|
||||
// 先查缓存是否有值
|
||||
String redisKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + authAppId;
|
||||
String authAccessToken = redisCache.getCacheObject(redisKey);
|
||||
@@ -285,7 +286,7 @@ public class AgentDevService {
|
||||
* @param refreshToken
|
||||
* @return
|
||||
*/
|
||||
public String getAuthTokenByRefreshToken(String authAppId, String refreshToken) {
|
||||
private String getAuthTokenByRefreshToken(String authAppId, String refreshToken) {
|
||||
GetComponentTokenDTO dto = GetComponentTokenDTO.builder()
|
||||
.appId(PLATFORM_APP_ID)
|
||||
.appSecret(PLATFORM_APP_SECRET)
|
||||
@@ -583,4 +584,31 @@ public class AgentDevService {
|
||||
// 将 authCode 存入缓存
|
||||
redisCache.setCacheObject(redisKey, authCode, Integer.parseInt(expiresIn), TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置小程序用户隐私保护指引
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
public String setPrivacySetting(PrivacySettingDTO dto) {
|
||||
// 获取用户接口调用令牌
|
||||
String authAccessToken = getAuthAccessToken(dto.getAuthAppId());
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=" + authAccessToken;
|
||||
List<UserInfoSetting> settingList = dto.getSettingList();
|
||||
// 转为 jsonArray
|
||||
JSONArray itemArray = JSONArray.parseArray(JSONObject.toJSONString(settingList));
|
||||
// 拼接参数
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("privacy_ver", dto.getPrivacyVer());
|
||||
jsonObject.put("setting_list", itemArray);
|
||||
jsonObject.put("owner_setting", dto.getOwnerSetting());
|
||||
|
||||
// 发送请求
|
||||
String result = HttpUtils.sendPost(url, JSONObject.toJSONString(jsonObject));
|
||||
// 转为 json 对象
|
||||
JSONObject resultJson = JSONObject.parseObject(result);
|
||||
|
||||
return resultJson.getString("errmsg");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user