mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-25 01:29:47 +08:00
新增 微信第三方平台 设置小程序用户隐私保护指引 接口
This commit is contained in:
@@ -278,4 +278,24 @@ public class AgentDevController extends BaseController {
|
|||||||
return response;
|
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.common.util.wxplatform.WXXmlToMapUtil;
|
||||||
import com.jsowell.pile.domain.agentDev.AuditItem;
|
import com.jsowell.pile.domain.agentDev.AuditItem;
|
||||||
import com.jsowell.pile.domain.agentDev.CategoryInfo;
|
import com.jsowell.pile.domain.agentDev.CategoryInfo;
|
||||||
|
import com.jsowell.pile.domain.agentDev.UserInfoSetting;
|
||||||
import com.jsowell.pile.dto.agentDev.*;
|
import com.jsowell.pile.dto.agentDev.*;
|
||||||
import com.jsowell.pile.vo.agentDev.AuthInfoVO;
|
import com.jsowell.pile.vo.agentDev.AuthInfoVO;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
@@ -265,7 +266,7 @@ public class AgentDevService {
|
|||||||
* @param authAppId
|
* @param authAppId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getAuthAccessToken(String authAppId) {
|
private String getAuthAccessToken(String authAppId) {
|
||||||
// 先查缓存是否有值
|
// 先查缓存是否有值
|
||||||
String redisKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + authAppId;
|
String redisKey = CacheConstants.AUTHORIZER_ACCESS_TOKEN + authAppId;
|
||||||
String authAccessToken = redisCache.getCacheObject(redisKey);
|
String authAccessToken = redisCache.getCacheObject(redisKey);
|
||||||
@@ -285,7 +286,7 @@ public class AgentDevService {
|
|||||||
* @param refreshToken
|
* @param refreshToken
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getAuthTokenByRefreshToken(String authAppId, String refreshToken) {
|
private String getAuthTokenByRefreshToken(String authAppId, String refreshToken) {
|
||||||
GetComponentTokenDTO dto = GetComponentTokenDTO.builder()
|
GetComponentTokenDTO dto = GetComponentTokenDTO.builder()
|
||||||
.appId(PLATFORM_APP_ID)
|
.appId(PLATFORM_APP_ID)
|
||||||
.appSecret(PLATFORM_APP_SECRET)
|
.appSecret(PLATFORM_APP_SECRET)
|
||||||
@@ -583,4 +584,31 @@ public class AgentDevService {
|
|||||||
// 将 authCode 存入缓存
|
// 将 authCode 存入缓存
|
||||||
redisCache.setCacheObject(redisKey, authCode, Integer.parseInt(expiresIn), TimeUnit.SECONDS);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.jsowell.pile.domain.agentDev;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收集方(开发者)信息配置
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/8/2 14:46
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class OwnerSetting {
|
||||||
|
/**
|
||||||
|
* 信息收集方(开发者)的手机号,4种联系方式至少要填一种
|
||||||
|
*/
|
||||||
|
@JSONField(name = "contact_phone")
|
||||||
|
private String contactPhone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 信息收集方(开发者)的邮箱地址,4种联系方式至少要填一种
|
||||||
|
*/
|
||||||
|
@JSONField(name = "contact_email")
|
||||||
|
private String contactEmail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 信息收集方(开发者)的qq号,4种联系方式至少要填一种
|
||||||
|
*/
|
||||||
|
@JSONField(name = "contact_qq")
|
||||||
|
private String contactQQ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 信息收集方(开发者)的微信号,4种联系方式至少要填一种
|
||||||
|
*/
|
||||||
|
@JSONField(name = "contact_weixin")
|
||||||
|
private String contactWeixin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储期限,指的是开发者收集用户信息存储多久。
|
||||||
|
* 如果不填则展示为【开发者承诺,除法律法规另有规定,开发者对你的信息保存期限应当为实现处理目的所必要的最短时间】,
|
||||||
|
* 如果填请填数字+天,例如“30天”,否则会出现87072的报错。
|
||||||
|
*/
|
||||||
|
@JSONField(name = "store_expire_timestamp")
|
||||||
|
private String storeExpireTimestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果开发者不使用微信提供的标准化用户隐私保护指引模板,
|
||||||
|
* 也可以上传自定义的用户隐私保护指引,通过uploadPrivacySetting接口上传后可获取media_id
|
||||||
|
*/
|
||||||
|
@JSONField(name = "ext_file_media_id")
|
||||||
|
private String extFileMediaId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知方式
|
||||||
|
* 指的是当开发者收集信息有变动时,通过该方式通知用户。这里服务商需要按照实际情况填写,例如通过弹窗或者公告或者其他方式。
|
||||||
|
*/
|
||||||
|
@JSONField(name = "notice_method")
|
||||||
|
private String noticeMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储地区
|
||||||
|
*/
|
||||||
|
@JSONField(name = "store_region")
|
||||||
|
private String storeRegion;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.jsowell.pile.domain.agentDev;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户信息配置
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/8/2 14:44
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserInfoSetting {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 该字段支持自定义
|
||||||
|
*/
|
||||||
|
@JSONField(name = "privacy_key")
|
||||||
|
private String privacyKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请填写收集该信息的用途。
|
||||||
|
* 例如privacy_key=Location(位置信息),那么privacy_text则填写收集位置信息的用途。
|
||||||
|
* 无需再带上“为了”或者“用于”这些字眼,小程序端的显示格式是为了xxx,因此开发者只需要直接填写用途即可。
|
||||||
|
*/
|
||||||
|
@JSONField(name = "privacy_text")
|
||||||
|
private String privacyText;
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.jsowell.pile.dto.agentDev;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import com.jsowell.pile.domain.agentDev.OwnerSetting;
|
||||||
|
import com.jsowell.pile.domain.agentDev.UserInfoSetting;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置小程序用户隐私保护指引DTO
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/8/2 14:42
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PrivacySettingDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户授权appId
|
||||||
|
*/
|
||||||
|
private String authAppId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户隐私保护指引的版本
|
||||||
|
* 1表示现网版本;2表示开发版。默认是2开发版
|
||||||
|
*/
|
||||||
|
@JSONField(name = "privacy_ver")
|
||||||
|
private int privacyVer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 要收集的用户信息配置,
|
||||||
|
* 可选择的用户信息类型参考下方详情。当privacy_ver传2或者不传时,setting_list是必填;当privacy_ver传1时,该参数不可传,否则会报错
|
||||||
|
*/
|
||||||
|
@JSONField(name = "setting_list")
|
||||||
|
private List<UserInfoSetting> settingList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收集方(开发者)信息配置
|
||||||
|
*/
|
||||||
|
@JSONField(name = "owner_setting")
|
||||||
|
private OwnerSetting ownerSetting;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user