-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
657 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaPrivacyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package me.chanjar.weixin.open.api; | ||
|
||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.open.bean.ma.privacy.GetPrivacySettingResult; | ||
import me.chanjar.weixin.open.bean.ma.privacy.SetPrivacySetting; | ||
import me.chanjar.weixin.open.bean.ma.privacy.UploadPrivacyFileResult; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* 微信第三方平台 小程序用户隐私保护指引接口 | ||
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/set_privacy_setting.html | ||
* | ||
* @author <a href="https://www.sacoc.cn">广州跨界</a> | ||
*/ | ||
public interface WxOpenMaPrivacyService { | ||
|
||
/** | ||
* 1 设置小程序用户隐私保护指引 | ||
*/ | ||
String OPEN_SET_PRIVACY_SETTING = "https://api.weixin.qq.com/cgi-bin/component/setprivacysetting"; | ||
|
||
/** | ||
* 2 查询小程序用户隐私保护指引 | ||
*/ | ||
String OPEN_GET_PRIVACY_SETTING = "https://api.weixin.qq.com/cgi-bin/component/getprivacysetting"; | ||
|
||
/** | ||
* 3 上传小程序用户隐私保护指引文件 | ||
*/ | ||
String OPEN_UPLOAD_PRIVACY_FILE = "https://api.weixin.qq.com/cgi-bin/component/uploadprivacyextfile"; | ||
|
||
|
||
/** | ||
* 查询小程序用户隐私保护指引 | ||
* 文档地址:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/get_privacy_setting.html | ||
* | ||
* @param privacyVer 1表示现网版本,即,传1则该接口返回的内容是现网版本的;2表示开发版,即,传2则该接口返回的内容是开发版本的。默认是2。 | ||
* @return 查询结果 | ||
* @throws WxErrorException 如果出错,抛出此异常 | ||
*/ | ||
GetPrivacySettingResult getPrivacySetting(@Nullable Integer privacyVer) throws WxErrorException; | ||
|
||
|
||
/** | ||
* 设置小程序用户隐私保护指引 | ||
* 文档地址:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/set_privacy_setting.html | ||
* | ||
* @param dto 参数对象 | ||
* @throws WxErrorException 如果出错,抛出此异常 | ||
*/ | ||
void setPrivacySetting(SetPrivacySetting dto) throws WxErrorException; | ||
|
||
|
||
/** | ||
* 上传小程序用户隐私保护指引文件 | ||
* 本接口用于上传自定义的小程序的用户隐私保护指引 | ||
* 仅限文本文件, 限制文件大小为不超过100kb,否则会报错 | ||
* 文档地址:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/upload_privacy_exfile.html | ||
* | ||
* @param content 文本文件内容 | ||
* @return 上传结果 | ||
* @throws WxErrorException 如果出错,抛出此异常 | ||
*/ | ||
UploadPrivacyFileResult uploadPrivacyFile(String content) throws WxErrorException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...n-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaPrivacyServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package me.chanjar.weixin.open.api.impl; | ||
|
||
import cn.binarywang.wx.miniapp.api.WxMaService; | ||
import lombok.AllArgsConstructor; | ||
import lombok.SneakyThrows; | ||
import me.chanjar.weixin.common.error.WxError; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.open.api.WxOpenMaPrivacyService; | ||
import me.chanjar.weixin.open.bean.ma.privacy.GetPrivacySettingResult; | ||
import me.chanjar.weixin.open.bean.ma.privacy.SetPrivacySetting; | ||
import me.chanjar.weixin.open.bean.ma.privacy.UploadPrivacyFileResult; | ||
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* 微信第三方平台 小程序用户隐私保护指引接口 | ||
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/set_privacy_setting.html | ||
* | ||
* @author <a href="https://www.sacoc.cn">广州跨界</a> | ||
*/ | ||
@AllArgsConstructor | ||
public class WxOpenMaPrivacyServiceImpl implements WxOpenMaPrivacyService { | ||
|
||
private final WxMaService wxMaService; | ||
|
||
|
||
@Override | ||
public GetPrivacySettingResult getPrivacySetting(@Nullable Integer privacyVer) throws WxErrorException { | ||
Map<String, Object> params = new HashMap<>(); | ||
if (privacyVer != null) { | ||
params.put("privacy_ver", privacyVer); | ||
} | ||
String json = wxMaService.post(OPEN_GET_PRIVACY_SETTING, params); | ||
return WxOpenGsonBuilder.create().fromJson(json, GetPrivacySettingResult.class); | ||
} | ||
|
||
@Override | ||
public void setPrivacySetting(SetPrivacySetting dto) throws WxErrorException { | ||
wxMaService.post(OPEN_SET_PRIVACY_SETTING, dto); | ||
} | ||
|
||
@SneakyThrows | ||
@Override | ||
public UploadPrivacyFileResult uploadPrivacyFile(String content) throws WxErrorException { | ||
// TODO 应实现通过InputStream上传的功能,一下代码暂时无法正常运行 | ||
// ByteArrayInputStream data = new ByteArrayInputStream(content.getBytes("GBK")); | ||
// GenericUploadRequestExecutor executor = new GenericUploadRequestExecutor(wxMaService.getRequestHttp(), "POST", "file", "/temp.txt"); | ||
// String json = wxMaService.execute(executor, OPEN_UPLOAD_PRIVACY_FILE, data); | ||
// return WxOpenGsonBuilder.create().fromJson(json, UploadPrivacyFileResult.class); | ||
throw new WxErrorException(new WxError(5003, "暂未实现用户隐私指引内容上传")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...va-open/src/main/java/me/chanjar/weixin/open/bean/ma/privacy/GetPrivacySettingResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package me.chanjar.weixin.open.bean.ma.privacy; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import me.chanjar.weixin.open.bean.result.WxOpenResult; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 查询小程序用户隐私保护指引 响应 | ||
* | ||
* @author <a href="https://www.sacoc.cn">广州跨界</a> | ||
*/ | ||
@Getter | ||
@Setter | ||
public class GetPrivacySettingResult extends WxOpenResult { | ||
|
||
/** | ||
* 代码是否存在, 0 不存在, 1 存在 。如果最近没有通过commit接口上传代码,则会出现 code_exist=0的情况。 | ||
*/ | ||
@SerializedName("code_exist") | ||
private Integer codeExist; | ||
|
||
/** | ||
* 代码检测出来的用户信息类型(privacy_key) | ||
*/ | ||
@SerializedName("privacy_list") | ||
private List<String> privacyList; | ||
|
||
/** | ||
* 要收集的用户信息配置 | ||
*/ | ||
@SerializedName("setting_list") | ||
private List<Setting> settingList; | ||
|
||
/** | ||
* 更新时间 | ||
*/ | ||
@SerializedName("update_time") | ||
private Long updateTime; | ||
|
||
/** | ||
* 收集方(开发者)信息配置 | ||
*/ | ||
@SerializedName("owner_setting") | ||
private PrivacyOwnerSetting ownerSetting; | ||
|
||
/** | ||
* 收集方(开发者)信息配置 | ||
*/ | ||
@SerializedName("privacy_desc") | ||
private PrivacyDesc privacyDesc; | ||
|
||
|
||
@Data | ||
public static class Setting { | ||
|
||
/** | ||
* 官方的可选值参考下方说明;该字段也支持自定义 | ||
* | ||
* @see PrivacyKeyEnum | ||
* @see PrivacyKeyEnum#getKey() | ||
*/ | ||
@SerializedName("privacy_key") | ||
private String privacyKey; | ||
|
||
/** | ||
* 请填写收集该信息的用途。例如privacy_key=Location(位置信息),那么privacy_text则填写收集位置信息的用途。 | ||
* 无需再带上“为了”或者“用于”这些字眼,小程序端的显示格式是为了xxx,因此开发者只需要直接填写用途即可。 | ||
*/ | ||
@SerializedName("privacy_text") | ||
private String privacyText; | ||
|
||
/** | ||
* 用户信息类型的中文名称 | ||
* | ||
* @see PrivacyKeyEnum#getDesc() () | ||
*/ | ||
@SerializedName("privacy_label") | ||
private String privacyLabel; | ||
} | ||
|
||
|
||
@Data | ||
public static class PrivacyDesc { | ||
|
||
/** | ||
* 用户信息类型 | ||
*/ | ||
@SerializedName("privacy_desc_list") | ||
private List<PrivacyDescItem> privacyDescList; | ||
} | ||
|
||
@Data | ||
public static class PrivacyDescItem { | ||
|
||
/** | ||
* 用户信息类型的英文key | ||
* | ||
* @see PrivacyKeyEnum | ||
* @see PrivacyKeyEnum#getKey() | ||
*/ | ||
@SerializedName("privacy_key") | ||
private String privacyKey; | ||
|
||
/** | ||
* 用户信息类型的中文描述 | ||
* | ||
* @see PrivacyKeyEnum#getDesc() | ||
*/ | ||
@SerializedName("privacy_desc") | ||
private String privacyDesc; | ||
} | ||
|
||
|
||
} |
62 changes: 62 additions & 0 deletions
62
weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/ma/privacy/PrivacyKeyEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package me.chanjar.weixin.open.bean.ma.privacy; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
/** | ||
* 隐私key枚举 | ||
* | ||
* @author <a href="https://www.sacoc.cn">广州跨界</a> | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
public enum PrivacyKeyEnum { | ||
|
||
USER_INFO("UserInfo", "用户信息(微信昵称、头像)"), | ||
|
||
LOCATION("Location", "位置信息"), | ||
|
||
ADDRESS("Address", "地址"), | ||
|
||
INVOICE("Invoice", "发票信息"), | ||
|
||
RUN_DATA("RunData", "微信运动数据"), | ||
|
||
RECORD("Record", "麦克风"), | ||
|
||
ALBUM("Album", "选中的照片或视频信息"), | ||
|
||
CAMERA("Camera", "摄像头"), | ||
|
||
PHONE_NUMBER("PhoneNumber", "手机号码"), | ||
|
||
CONTACT("Contact", "通讯录(仅写入)权限"), | ||
|
||
DEVICE_INFO("DeviceInfo", "设备信息"), | ||
|
||
EXID_NUMBER("EXIDNumber", "身份证号码"), | ||
|
||
EX_ORDER_INFO("EXOrderInfo", "订单信息"), | ||
|
||
EX_USER_PUBLISH_CONTENT("EXUserPublishContent", "发布内容"), | ||
|
||
EX_USER_FOLLOW_ACCT("EXUserFollowAcct", "所关注账号"), | ||
|
||
EX_USER_OP_LOG("EXUserOpLog", "操作日志"), | ||
|
||
ALBUM_WRITE_ONLY("AlbumWriteOnly", "相册(仅写入)权限"), | ||
|
||
LICENSE_PLATE("LicensePlate", "车牌号"), | ||
|
||
BLUE_TOOTH("BlueTooth", "蓝牙"), | ||
|
||
CALENDAR_WRITE_ONLY("CalendarWriteOnly", "日历(仅写入)权限"), | ||
|
||
EMAIL("Email", "邮箱"), | ||
|
||
MESSAGE_FILE("MessageFile", "选中的文件"), | ||
; | ||
|
||
private final String key; | ||
private final String desc; | ||
} |
Oops, something went wrong.