repo stringclasses 1k
values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 6
values | commit_sha stringclasses 1k
values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpBatchUpdateStudentRequest.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpBatchUpdateStudentRequest.java | package me.chanjar.weixin.cp.bean.school.user;
import com.google.gson.annotations.SerializedName;
import lombok.*;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 批量更新学生请求.
*
* @author Wang_Wong created on 2022-07-01
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpBatchUpdateStudentRequest implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;
@SerializedName("students")
private List<Student> students;
/**
* The type Student.
*/
@Setter
@Getter
public static class Student implements Serializable {
@SerializedName("student_userid")
private String studentUserId;
@SerializedName("new_student_userid")
private String newStudentUserId;
@SerializedName("name")
private String name;
@SerializedName("department")
private List<Integer> department;
/**
* From json student.
*
* @param json the json
* @return the student
*/
public static Student fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Student.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* From json wx cp batch update student request.
*
* @param json the json
* @return the wx cp batch update student request
*/
public static WxCpBatchUpdateStudentRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpBatchUpdateStudentRequest.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpUserListResult.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpUserListResult.java | package me.chanjar.weixin.cp.bean.school.user;
import com.google.gson.annotations.SerializedName;
import lombok.*;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 获取部门成员详情返回结果.
*
* @author Wang_Wong created on 2022-07-13
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpUserListResult extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;
@SerializedName("students")
private List<Student> students;
/**
* The type Parent.
*/
@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Parent implements Serializable {
@SerializedName("parent_userid")
private String parentUserId;
@SerializedName("relation")
private String relation;
@SerializedName("mobile")
private String mobile;
@SerializedName("external_userid")
private String externalUserId;
@SerializedName("is_subscribe")
private Integer isSubscribe;
/**
* From json parent.
*
* @param json the json
* @return the parent
*/
public static Parent fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Parent.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* The type Student.
*/
@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Student implements Serializable {
@SerializedName("student_userid")
private String studentUserId;
@SerializedName("name")
private String name;
@SerializedName("department")
private List<Integer> department;
@SerializedName("parents")
private List<Parent> parents;
/**
* From json student.
*
* @param json the json
* @return the student
*/
public static Student fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Student.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* From json wx cp user list result.
*
* @param json the json
* @return the wx cp user list result
*/
public static WxCpUserListResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpUserListResult.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateDepartment.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateDepartment.java | package me.chanjar.weixin.cp.bean.school.user;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* 创建部门返回结果.
*
* @author Wang_Wong
*/
@Data
public class WxCpCreateDepartment extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625140879571L;
@SerializedName("id")
private Integer id;
/**
* From json wx cp create department.
*
* @param json the json
* @return the wx cp create department
*/
public static WxCpCreateDepartment fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpCreateDepartment.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpSetUpgradeInfo.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpSetUpgradeInfo.java | package me.chanjar.weixin.cp.bean.school.user;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* 修改自动升年级的配置 返回结果.
*
* @author Wang_Wong
*/
@Data
public class WxCpSetUpgradeInfo extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625140879571L;
@SerializedName("next_upgrade_time")
private Long nextUpgradeTime;
/**
* From json wx cp set upgrade info.
*
* @param json the json
* @return the wx cp set upgrade info
*/
public static WxCpSetUpgradeInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSetUpgradeInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpSubscribeQrCode.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpSubscribeQrCode.java | package me.chanjar.weixin.cp.bean.school.user;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* 获取「学校通知」二维码 返回结果.
*
* @author Wang_Wong
*/
@Data
public class WxCpSubscribeQrCode extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625140879571L;
@SerializedName("qrcode_big")
private String qrCodeBig;
@SerializedName("qrcode_middle")
private String qrCodeMiddle;
@SerializedName("qrcode_thumb")
private String qrCodeThumb;
/**
* From json wx cp subscribe qr code.
*
* @param json the json
* @return the wx cp subscribe qr code
*/
public static WxCpSubscribeQrCode fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSubscribeQrCode.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportAnswer.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportAnswer.java | package me.chanjar.weixin.cp.bean.school.health;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 获取用户填写答案.
* https://developer.work.weixin.qq.com/document/path/93679
*
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
*/
@Data
public class WxCpGetReportAnswer extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;
@SerializedName("answers")
private List<Answer> answers;
/**
* The type Answer.
*/
@Getter
@Setter
public static class Answer implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("userid")
private String userId;
@SerializedName("id_type")
private Integer idType;
@SerializedName("report_time")
private Long reportTime;
@SerializedName("student_userid")
private String studentUserId;
@SerializedName("parent_userid")
private String parentUserId;
@SerializedName("report_values")
private List<ReportValue> reportValues;
/**
* From json answer.
*
* @param json the json
* @return the answer
*/
public static Answer fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Answer.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* The type Report value.
*/
@Getter
@Setter
public static class ReportValue implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("question_id")
private Integer questionId;
@SerializedName("single_choice")
private Integer singleChoice;
@SerializedName("multi_choice")
private List<Integer> multiChoice;
@SerializedName("text")
private String text;
@SerializedName("fileid")
private List<String> fileId;
/**
* From json report value.
*
* @param json the json
* @return the report value
*/
public static ReportValue fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, ReportValue.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* From json wx cp get report answer.
*
* @param json the json
* @return the wx cp get report answer
*/
public static WxCpGetReportAnswer fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportAnswer.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportJobIds.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportJobIds.java | package me.chanjar.weixin.cp.bean.school.health;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 获取健康上报使用统计.
*
* @author Wang_Wong
*/
@Data
public class WxCpGetReportJobIds extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;
@SerializedName("ending")
private Integer ending;
@SerializedName("jobids")
private List<String> jobIds;
/**
* From json wx cp get report job ids.
*
* @param json the json
* @return the wx cp get report job ids
*/
public static WxCpGetReportJobIds fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportJobIds.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportJobInfo.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetReportJobInfo.java | package me.chanjar.weixin.cp.bean.school.health;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 获取健康上报任务详情.
*
* @author Wang_Wong
*/
@Data
public class WxCpGetReportJobInfo extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;
@SerializedName("job_info")
private JobInfo jobInfo;
/**
* The type Job info.
*/
@Getter
@Setter
public static class JobInfo implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("title")
private String title;
@SerializedName("creator")
private String creator;
@SerializedName("type")
private Integer type;
@SerializedName("report_type")
private Integer reportType;
@SerializedName("skip_weekend")
private Integer skipWeekend;
@SerializedName("finish_cnt")
private Integer finishCnt;
@SerializedName("apply_range")
private ApplyRange applyRange;
@SerializedName("report_to")
private ReportTo reportTo;
@SerializedName("question_templates")
private List<QuestionTemplate> questionTemplates;
/**
* From json job info.
*
* @param json the json
* @return the job info
*/
public static JobInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, JobInfo.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* The type Apply range.
*/
@Getter
@Setter
public static class ApplyRange implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("userids")
private List<String> userIds;
@SerializedName("partyids")
private List<Integer> partyIds;
/**
* From json apply range.
*
* @param json the json
* @return the apply range
*/
public static ApplyRange fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, ApplyRange.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* The type Report to.
*/
@Getter
@Setter
public static class ReportTo implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("userids")
private List<String> userIds;
/**
* From json report to.
*
* @param json the json
* @return the report to
*/
public static ReportTo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, ReportTo.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* The type Question template.
*/
@Getter
@Setter
public static class QuestionTemplate implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("question_id")
private Integer questionId;
@SerializedName("question_type")
private Integer questionType;
@SerializedName("is_required")
private Integer isRequired;
@SerializedName("title")
private String title;
@SerializedName("option_list")
private List<OptionList> optionList;
/**
* From json question template.
*
* @param json the json
* @return the question template
*/
public static QuestionTemplate fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, QuestionTemplate.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* The type Option list.
*/
@Getter
@Setter
public static class OptionList implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("option_id")
private Integer optionId;
@SerializedName("option_text")
private String optionText;
/**
* From json option list.
*
* @param json the json
* @return the option list
*/
public static OptionList fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, OptionList.class);
}
/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
/**
* From json wx cp get report job info.
*
* @param json the json
* @return the wx cp get report job info
*/
public static WxCpGetReportJobInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetReportJobInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetHealthReportStat.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/health/WxCpGetHealthReportStat.java | package me.chanjar.weixin.cp.bean.school.health;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* 获取健康上报使用统计.
*
* @author Wang_Wong
*/
@Data
public class WxCpGetHealthReportStat extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;
@SerializedName("pv")
private Integer pv;
@SerializedName("uv")
private Integer uv;
/**
* From json wx cp get health report stat.
*
* @param json the json
* @return the wx cp get health report stat
*/
public static WxCpGetHealthReportStat fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetHealthReportStat.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageHandler.java | package me.chanjar.weixin.cp.message;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
import java.util.Map;
/**
* 处理微信推送消息的处理器接口
*
* @author Daniel Qian
*/
public interface WxCpMessageHandler {
/**
* Handle wx cp xml out message.
*
* @param wxMessage the wx message
* @param context 上下文,如果handler或interceptor之间有信息要传递,可以用这个
* @param wxCpService the wx cp service
* @param sessionManager the session manager
* @return xml格式的消息 ,如果在异步规则里处理的话,可以返回null
* @throws WxErrorException the wx error exception
*/
WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
Map<String, Object> context,
WxCpService wxCpService,
WxSessionManager sessionManager) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java | package me.chanjar.weixin.cp.message;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateCheckerSingleton;
import me.chanjar.weixin.common.session.InternalSession;
import me.chanjar.weixin.common.session.InternalSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.LogExceptionHandler;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
import java.util.concurrent.*;
/**
* <pre>
* 微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理
*
* 说明:
* 1. 配置路由规则时要按照从细到粗的原则,否则可能消息可能会被提前处理
* 2. 默认情况下消息只会被处理一次,除非使用 {@link WxCpMessageRouterRule#next()}
* 3. 规则的结束必须用{@link WxCpMessageRouterRule#end()}或者{@link WxCpMessageRouterRule#next()},否则不会生效
*
* 使用方法:
* WxCpMessageRouter router = new WxCpMessageRouter();
* router
* .rule()
* .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT")
* .interceptor(interceptor, ...).handler(handler, ...)
* .end()
* .rule()
* // 另外一个匹配规则
* .end()
* ;
*
* // 将WxXmlMessage交给消息路由器
* router.route(message);
*
* </pre>
*
* @author Daniel Qian
*/
@Slf4j
public class WxCpMessageRouter {
private static final int DEFAULT_THREAD_POOL_SIZE = 100;
private final List<WxCpMessageRouterRule> rules = new ArrayList<>();
private final WxCpService wxCpService;
private ExecutorService executorService;
private WxMessageDuplicateChecker messageDuplicateChecker;
private WxSessionManager sessionManager;
private WxErrorExceptionHandler exceptionHandler;
/**
* 构造方法.
*
* @param wxCpService the wx cp service
*/
public WxCpMessageRouter(WxCpService wxCpService) {
this.wxCpService = wxCpService;
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("WxCpMessageRouter-pool-%d").build();
this.executorService = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_SIZE,
0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), namedThreadFactory);
this.messageDuplicateChecker = WxMessageInMemoryDuplicateCheckerSingleton.getInstance();
this.sessionManager = wxCpService.getSessionManager();
this.exceptionHandler = new LogExceptionHandler();
}
/**
* 使用自定义的 {@link ExecutorService}.
*
* @param wxMpService the wx mp service
* @param executorService the executor service
*/
public WxCpMessageRouter(WxCpService wxMpService, ExecutorService executorService) {
this.wxCpService = wxMpService;
this.executorService = executorService;
this.messageDuplicateChecker = WxMessageInMemoryDuplicateCheckerSingleton.getInstance();
this.sessionManager = wxCpService.getSessionManager();
this.exceptionHandler = new LogExceptionHandler();
}
/**
* 系统退出前,应该调用该方法
*/
public void shutDownExecutorService() {
this.executorService.shutdown();
}
/**
* 系统退出前,应该调用该方法,增加了超时时间检测
*
* @param second the second
*/
public void shutDownExecutorService(Integer second) {
this.executorService.shutdown();
try {
if (!this.executorService.awaitTermination(second, TimeUnit.SECONDS)) {
this.executorService.shutdownNow();
if (!this.executorService.awaitTermination(second, TimeUnit.SECONDS))
log.error("线程池未关闭!");
}
} catch (InterruptedException ie) {
this.executorService.shutdownNow();
Thread.currentThread().interrupt();
}
}
/**
* <pre>
* 设置自定义的 {@link ExecutorService}
* 如果不调用该方法,默认使用 Executors.newFixedThreadPool(100)
* </pre>
*
* @param executorService the executor service
*/
public void setExecutorService(ExecutorService executorService) {
this.executorService = executorService;
}
/**
* <pre>
* 设置自定义的 {@link me.chanjar.weixin.common.api.WxMessageDuplicateChecker}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker}
* </pre>
*
* @param messageDuplicateChecker the message duplicate checker
*/
public void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicateChecker) {
this.messageDuplicateChecker = messageDuplicateChecker;
}
/**
* <pre>
* 设置自定义的{@link me.chanjar.weixin.common.session.WxSessionManager}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.session.StandardSessionManager}
* </pre>
*
* @param sessionManager the session manager
*/
public void setSessionManager(WxSessionManager sessionManager) {
this.sessionManager = sessionManager;
}
/**
* <pre>
* 设置自定义的{@link me.chanjar.weixin.common.api.WxErrorExceptionHandler}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.util.LogExceptionHandler}
* </pre>
*
* @param exceptionHandler the exception handler
*/
public void setExceptionHandler(WxErrorExceptionHandler exceptionHandler) {
this.exceptionHandler = exceptionHandler;
}
/**
* Gets rules.
*
* @return the rules
*/
List<WxCpMessageRouterRule> getRules() {
return this.rules;
}
/**
* 开始一个新的Route规则.
*
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule rule() {
return new WxCpMessageRouterRule(this);
}
/**
* 处理微信消息.
*
* @param wxMessage the wx message
* @param context the context
* @return the wx cp xml out message
*/
public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage, final Map<String, Object> context) {
if (isMsgDuplicated(wxMessage)) {
// 如果是重复消息,那么就不做处理
return null;
}
final List<WxCpMessageRouterRule> matchRules = new ArrayList<>();
// 收集匹配的规则
for (final WxCpMessageRouterRule rule : this.rules) {
if (rule.test(wxMessage)) {
matchRules.add(rule);
if (!rule.isReEnter()) {
break;
}
}
}
if (matchRules.isEmpty()) {
return null;
}
WxCpXmlOutMessage res = null;
final List<Future<?>> futures = new ArrayList<>();
for (final WxCpMessageRouterRule rule : matchRules) {
// 返回最后一个非异步的rule的执行结果
if (rule.isAsync()) {
futures.add(
this.executorService.submit(() -> {
rule.service(wxMessage, context, WxCpMessageRouter.this.wxCpService,
WxCpMessageRouter.this.sessionManager, WxCpMessageRouter.this.exceptionHandler);
})
);
} else {
res = rule.service(wxMessage, context, this.wxCpService, this.sessionManager, this.exceptionHandler);
// 在同步操作结束,session访问结束
log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName());
sessionEndAccess(wxMessage);
}
}
if (!futures.isEmpty()) {
this.executorService.submit(() -> {
for (Future<?> future : futures) {
try {
future.get();
log.debug("End session access: async=true, sessionId={}", wxMessage.getFromUserName());
// 异步操作结束,session访问结束
sessionEndAccess(wxMessage);
} catch (InterruptedException e) {
log.error("Error happened when wait task finish", e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
log.error("Error happened when wait task finish", e);
}
}
});
}
return res;
}
/**
* 处理微信消息.
*
* @param wxMessage the wx message
* @return the wx cp xml out message
*/
public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
return this.route(wxMessage, new HashMap<>(2));
}
protected boolean isMsgDuplicated(WxCpXmlMessage wxMessage) {
StringBuilder messageId = new StringBuilder();
if (wxMessage.getMsgId() == null) {
messageId.append(wxMessage.getCreateTime())
.append("-").append(StringUtils.trimToEmpty(String.valueOf(wxMessage.getAgentId())))
.append("-").append(wxMessage.getFromUserName())
.append("-").append(StringUtils.trimToEmpty(wxMessage.getEventKey()))
.append("-").append(StringUtils.trimToEmpty(wxMessage.getEvent()));
} else {
messageId.append(wxMessage.getMsgId())
.append("-").append(wxMessage.getCreateTime())
.append("-").append(wxMessage.getFromUserName());
}
if (Objects.nonNull(wxMessage.getApprovalInfo())) {
append(messageId, wxMessage.getApprovalInfo().getSpNo());
}
append(messageId, wxMessage.getUserId());
append(messageId, wxMessage.getChangeType());
append(messageId, wxMessage.getTagId());
append(messageId, wxMessage.getId());
append(messageId, wxMessage.getChatId());
append(messageId, wxMessage.getExternalUserId());
return this.messageDuplicateChecker.isDuplicate(messageId.toString());
}
private void append(StringBuilder sb, String value) {
if (StringUtils.isNotEmpty(value)) {
sb.append("-").append(value);
}
}
/**
* 对session的访问结束.
*/
private void sessionEndAccess(WxCpXmlMessage wxMessage) {
InternalSession session = ((InternalSessionManager) this.sessionManager).findSession(wxMessage.getFromUserName());
if (session != null) {
session.endAccess();
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageMatcher.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageMatcher.java | package me.chanjar.weixin.cp.message;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
/**
* 消息匹配器,用在消息路由的时候
*
* @author Daniel Qian
*/
public interface WxCpMessageMatcher {
/**
* 消息是否匹配某种模式
*
* @param message the message
* @return the boolean
*/
boolean match(WxCpXmlMessage message);
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageInterceptor.java | package me.chanjar.weixin.cp.message;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import java.util.Map;
/**
* 微信消息拦截器,可以用来做验证
*
* @author Daniel Qian
*/
public interface WxCpMessageInterceptor {
/**
* 拦截微信消息
*
* @param wxMessage the wx message
* @param context 上下文,如果handler或interceptor之间有信息要传递,可以用这个
* @param wxCpService the wx cp service
* @param sessionManager the session manager
* @return true代表OK ,false代表不OK
* @throws WxErrorException the wx error exception
*/
boolean intercept(WxCpXmlMessage wxMessage,
Map<String, Object> context,
WxCpService wxCpService,
WxSessionManager sessionManager) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouterRule.java | package me.chanjar.weixin.cp.message;
import lombok.Data;
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
import java.util.regex.Pattern;
/**
* The type Wx cp message router rule.
*
* @author Daniel Qian
*/
@Data
public class WxCpMessageRouterRule {
private final WxCpMessageRouter routerBuilder;
private boolean async = true;
private String fromUser;
private String msgType;
private String event;
private String eventKey;
private String eventKeyRegex;
private String content;
private String rContent;
private WxCpMessageMatcher matcher;
private boolean reEnter = false;
private Integer agentId;
private List<WxCpMessageHandler> handlers = new ArrayList<>();
private List<WxCpMessageInterceptor> interceptors = new ArrayList<>();
/**
* Instantiates a new Wx cp message router rule.
*
* @param routerBuilder the router builder
*/
protected WxCpMessageRouterRule(WxCpMessageRouter routerBuilder) {
this.routerBuilder = routerBuilder;
}
/**
* 设置是否异步执行,默认是true
*
* @param async the async
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule async(boolean async) {
this.async = async;
return this;
}
/**
* 如果agentId匹配
*
* @param agentId the agent id
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule agentId(Integer agentId) {
this.agentId = agentId;
return this;
}
/**
* 如果msgType等于某值
*
* @param msgType the msg type
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule msgType(String msgType) {
this.msgType = msgType;
return this;
}
/**
* 如果event等于某值
*
* @param event the event
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule event(String event) {
this.event = event;
return this;
}
/**
* 如果eventKey等于某值
*
* @param eventKey the event key
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule eventKey(String eventKey) {
this.eventKey = eventKey;
return this;
}
/**
* 如果eventKey匹配该正则表达式
*
* @param regex the regex
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule eventKeyRegex(String regex) {
this.eventKeyRegex = regex;
return this;
}
/**
* 如果content等于某值
*
* @param content the content
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule content(String content) {
this.content = content;
return this;
}
/**
* 如果content匹配该正则表达式
*
* @param regex the regex
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule rContent(String regex) {
this.rContent = regex;
return this;
}
/**
* 如果fromUser等于某值
*
* @param fromUser the from user
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule fromUser(String fromUser) {
this.fromUser = fromUser;
return this;
}
/**
* 如果消息匹配某个matcher,用在用户需要自定义更复杂的匹配规则的时候
*
* @param matcher the matcher
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule matcher(WxCpMessageMatcher matcher) {
this.matcher = matcher;
return this;
}
/**
* 设置微信消息拦截器
*
* @param interceptor the interceptor
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule interceptor(WxCpMessageInterceptor interceptor) {
return interceptor(interceptor, (WxCpMessageInterceptor[]) null);
}
/**
* 设置微信消息拦截器
*
* @param interceptor the interceptor
* @param otherInterceptors the other interceptors
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule interceptor(WxCpMessageInterceptor interceptor,
WxCpMessageInterceptor... otherInterceptors) {
this.interceptors.add(interceptor);
if (otherInterceptors != null && otherInterceptors.length > 0) {
Collections.addAll(this.interceptors, otherInterceptors);
}
return this;
}
/**
* 设置微信消息处理器
*
* @param handler the handler
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule handler(WxCpMessageHandler handler) {
return handler(handler, (WxCpMessageHandler[]) null);
}
/**
* 设置微信消息处理器
*
* @param handler the handler
* @param otherHandlers the other handlers
* @return the wx cp message router rule
*/
public WxCpMessageRouterRule handler(WxCpMessageHandler handler, WxCpMessageHandler... otherHandlers) {
this.handlers.add(handler);
if (otherHandlers != null && otherHandlers.length > 0) {
Collections.addAll(this.handlers, otherHandlers);
}
return this;
}
/**
* 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则
*
* @return the wx cp message router
*/
public WxCpMessageRouter end() {
this.routerBuilder.getRules().add(this);
return this.routerBuilder;
}
/**
* 规则结束,但是消息还会进入其他规则
*
* @return the wx cp message router
*/
public WxCpMessageRouter next() {
this.reEnter = true;
return end();
}
/**
* Test boolean.
*
* @param wxMessage the wx message
* @return the boolean
*/
protected boolean test(WxCpXmlMessage wxMessage) {
return
(this.fromUser == null || this.fromUser.equals(wxMessage.getFromUserName()))
&&
(this.agentId == null || this.agentId.equals(Integer.valueOf(wxMessage.getAgentId())))
&&
(this.msgType == null || this.msgType.equalsIgnoreCase(wxMessage.getMsgType()))
&&
(this.event == null || this.event.equalsIgnoreCase(wxMessage.getEvent()))
&&
(this.eventKey == null || this.eventKey.equalsIgnoreCase(wxMessage.getEventKey()))
&&
(this.eventKeyRegex == null || Pattern.matches(this.eventKeyRegex,
StringUtils.trimToEmpty(wxMessage.getEventKey())))
&&
(this.content == null || this.content.equals(StringUtils.trimToNull(wxMessage.getContent())))
&&
(this.rContent == null || Pattern.matches(this.rContent, StringUtils.trimToEmpty(wxMessage.getContent())))
&&
(this.matcher == null || this.matcher.match(wxMessage))
;
}
/**
* 处理微信推送过来的消息
*
* @param wxMessage the wx message
* @param context the context
* @param wxCpService the wx cp service
* @param sessionManager the session manager
* @param exceptionHandler the exception handler
* @return true 代表继续执行别的router,false 代表停止执行别的router
*/
protected WxCpXmlOutMessage service(WxCpXmlMessage wxMessage,
Map<String, Object> context,
WxCpService wxCpService,
WxSessionManager sessionManager,
WxErrorExceptionHandler exceptionHandler) {
if (context == null) {
context = new HashMap<>();
}
try {
// 如果拦截器不通过
for (WxCpMessageInterceptor interceptor : this.interceptors) {
if (!interceptor.intercept(wxMessage, context, wxCpService, sessionManager)) {
return null;
}
}
// 交给handler处理
WxCpXmlOutMessage res = null;
for (WxCpMessageHandler handler : this.handlers) {
// 返回最后handler的结果
res = handler.handle(wxMessage, context, wxCpService, sessionManager);
}
return res;
} catch (WxErrorException e) {
exceptionHandler.handle(e);
}
return null;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpConfigStorage.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpConfigStorage.java | package me.chanjar.weixin.cp.config;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
import java.io.File;
import java.util.concurrent.locks.Lock;
/**
* 微信客户端(第三方应用)配置存储
*
* @author zhenjun cai
*/
public interface WxCpTpConfigStorage {
/**
* 设置企业微信服务器 baseUrl.
* 默认值是 https://qyapi.weixin.qq.com , 如果使用默认值,则不需要调用 setBaseApiUrl
*
* @param baseUrl 企业微信服务器 Url
*/
void setBaseApiUrl(String baseUrl);
/**
* 读取企业微信 API Url.
* 支持私有化企业微信服务器.
*
* @param path the path
* @return the api url
*/
String getApiUrl(String path);
/**
* 第三方应用的suite access token相关
*
* @return the suite access token
*/
String getSuiteAccessToken();
/**
* 获取suite_access_token和剩余过期时间
*
* @return suite access token and the remaining expiration time
*/
WxAccessToken getSuiteAccessTokenEntity();
/**
* Is suite access token expired boolean.
*
* @return the boolean
*/
boolean isSuiteAccessTokenExpired();
/**
* Expire suite access token.
*/
//强制将suite access token过期掉.
void expireSuiteAccessToken();
/**
* Update suite access token.
*
* @param suiteAccessToken the suite access token
*/
void updateSuiteAccessToken(WxAccessToken suiteAccessToken);
/**
* Update suite access token.
*
* @param suiteAccessToken the suite access token
* @param expiresInSeconds the expires in seconds
*/
void updateSuiteAccessToken(String suiteAccessToken, int expiresInSeconds);
/**
* 第三方应用的suite ticket相关
*
* @return the suite ticket
*/
String getSuiteTicket();
/**
* Is suite ticket expired boolean.
*
* @return the boolean
*/
boolean isSuiteTicketExpired();
/**
* Expire suite ticket.
*/
//强制将suite ticket过期掉.
void expireSuiteTicket();
/**
* Update suite ticket.
*
* @param suiteTicket the suite ticket
* @param expiresInSeconds the expires in seconds
*/
//应该是线程安全的
void updateSuiteTicket(String suiteTicket, int expiresInSeconds);
/**
* 第三方应用的其他配置,来自于企微配置
*
* @return the suite id
*/
String getSuiteId();
/**
* Gets suite secret.
*
* @return the suite secret
*/
String getSuiteSecret();
/**
* Gets token.
*
* @return the token
*/
// 第三方应用的token,用来检查应用的签名
String getToken();
/**
* Gets aes key.
*
* @return the aes key
*/
//第三方应用的EncodingAESKey,用来检查签名
String getEncodingAESKey();
/**
* 企微服务商企业ID & 企业secret
*
* @return the corp id
*/
String getCorpId();
/**
* Gets corp secret.
*
* @return the corp secret
*/
String getCorpSecret();
/**
* Sets provider secret.
*
* @param providerSecret the provider secret
*/
void setProviderSecret(String providerSecret);
/**
* 服务商secret
*
* @return the provider secret
*/
String getProviderSecret();
/**
* 授权企业的access token相关
*
* @param authCorpId the auth corp id
* @return the access token
*/
String getAccessToken(String authCorpId);
/**
* Gets access token entity.
*
* @param authCorpId the auth corp id
* @return the access token entity
*/
WxAccessToken getAccessTokenEntity(String authCorpId);
/**
* Is access token expired boolean.
*
* @param authCorpId the auth corp id
* @return the boolean
*/
boolean isAccessTokenExpired(String authCorpId);
/**
* Expire access token.
*
* @param authCorpId the auth corp id
*/
void expireAccessToken(String authCorpId);
/**
* Update access token.
*
* @param authCorpId the auth corp id
* @param accessToken the access token
* @param expiredInSeconds the expired in seconds
*/
void updateAccessToken(String authCorpId, String accessToken, int expiredInSeconds);
/**
* 授权企业的js api ticket相关
*
* @param authCorpId the auth corp id
* @return the auth corp js api ticket
*/
String getAuthCorpJsApiTicket(String authCorpId);
/**
* Is auth corp js api ticket expired boolean.
*
* @param authCorpId the auth corp id
* @return the boolean
*/
boolean isAuthCorpJsApiTicketExpired(String authCorpId);
/**
* Expire auth corp js api ticket.
*
* @param authCorpId the auth corp id
*/
void expireAuthCorpJsApiTicket(String authCorpId);
/**
* Update auth corp js api ticket.
*
* @param authCorpId the auth corp id
* @param jsApiTicket the js api ticket
* @param expiredInSeconds the expired in seconds
*/
void updateAuthCorpJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds);
/**
* 授权企业的第三方应用js api ticket相关
*
* @param authCorpId the auth corp id
* @return the auth suite js api ticket
*/
String getAuthSuiteJsApiTicket(String authCorpId);
/**
* Is auth suite js api ticket expired boolean.
*
* @param authCorpId the auth corp id
* @return the boolean
*/
boolean isAuthSuiteJsApiTicketExpired(String authCorpId);
/**
* Expire auth suite js api ticket.
*
* @param authCorpId the auth corp id
*/
void expireAuthSuiteJsApiTicket(String authCorpId);
/**
* Update auth suite js api ticket.
*
* @param authCorpId the auth corp id
* @param jsApiTicket the js api ticket
* @param expiredInSeconds the expired in seconds
*/
void updateAuthSuiteJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds);
/**
* Is provider token expired boolean.
*
* @return the boolean
*/
boolean isProviderTokenExpired();
/**
* Update provider token.
*
* @param providerToken the provider token
* @param expiredInSeconds the expired in seconds
*/
void updateProviderToken(String providerToken, int expiredInSeconds);
/**
* Gets provider token.
*
* @return the provider token
*/
String getProviderToken();
/**
* Gets provider token entity.
*
* @return the provider token entity
*/
WxCpProviderToken getProviderTokenEntity();
/**
* Expire provider token.
*/
// 强制过期
void expireProviderToken();
/**
* 网络代理相关
*
* @return the http proxy host
*/
String getHttpProxyHost();
/**
* Gets http proxy port.
*
* @return the http proxy port
*/
int getHttpProxyPort();
/**
* Gets http proxy username.
*
* @return the http proxy username
*/
String getHttpProxyUsername();
/**
* Gets http proxy password.
*
* @return the http proxy password
*/
String getHttpProxyPassword();
/**
* Gets apache http client builder.
*
* @return the apache http client builder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder();
/**
* Auto refresh token boolean.
*
* @return the boolean
*/
boolean autoRefreshToken();
/**
* Gets tmp dir file.
*
* @return the tmp dir file
*/
// 毫无相关性的代码
@Deprecated
File getTmpDirFile();
/**
* Gets provider access token lock.
*
* @return the provider access token lock
*/
Lock getProviderAccessTokenLock();
/**
* Gets suite access token lock.
*
* @return the suite access token lock
*/
Lock getSuiteAccessTokenLock();
/**
* Gets access token lock.
*
* @param authCorpId the auth corp id
* @return the access token lock
*/
Lock getAccessTokenLock(String authCorpId);
/**
* Gets auth corp jsapi ticket lock.
*
* @param authCorpId the auth corp id
* @return the auth corp jsapi ticket lock
*/
Lock getAuthCorpJsapiTicketLock(String authCorpId);
/**
* Gets suite jsapi ticket lock.
*
* @param authCorpId the auth corp id
* @return the suite jsapi ticket lock
*/
Lock getSuiteJsapiTicketLock(String authCorpId);
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpCorpGroupConfigStorage.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpCorpGroupConfigStorage.java | package me.chanjar.weixin.cp.config;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import java.util.concurrent.locks.Lock;
/**
* 微信客户端(企业互联)配置
*
* @author libo
*/
public interface WxCpCorpGroupConfigStorage {
/**
* 设置企业微信服务器 baseUrl.
* 默认值是 https://qyapi.weixin.qq.com , 如果使用默认值,则不需要调用 setBaseApiUrl
*
* @param baseUrl 企业微信服务器 Url
*/
void setBaseApiUrl(String baseUrl);
/**
* 读取企业微信 API Url.
* 支持私有化企业微信服务器.
*
* @param path the path
* @return the api url
*/
String getApiUrl(String path);
/**
* Update corp access token.
*
* @param corpId
* @param agentId
* @param corpAccessToken the corp access token
* @param expiresInSeconds the expires in seconds
*/
void updateCorpAccessToken(String corpId, Integer agentId, String corpAccessToken, int expiresInSeconds);
/**
* 授权企业的access token相关
*
* @param corpId the corp id
* @param agentId
* @return the access token
*/
String getCorpAccessToken(String corpId, Integer agentId);
/**
* Gets access token entity.
*
* @param corpId the corp id
* @param agentId
* @return the access token entity
*/
WxAccessToken getCorpAccessTokenEntity(String corpId, Integer agentId);
/**
* Is access token expired boolean.
*
* @param corpId the corp id
* @param agentId
* @return the boolean
*/
boolean isCorpAccessTokenExpired(String corpId, Integer agentId);
/**
* Expire access token.
*
* @param corpId the corp id
* @param agentId
*/
void expireCorpAccessToken(String corpId, Integer agentId);
/**
* 网络代理相关
*
* @return the http proxy host
*/
String getHttpProxyHost();
/**
* Gets http proxy port.
*
* @return the http proxy port
*/
int getHttpProxyPort();
/**
* Gets http proxy username.
*
* @return the http proxy username
*/
String getHttpProxyUsername();
/**
* Gets http proxy password.
*
* @return the http proxy password
*/
String getHttpProxyPassword();
/**
* Gets apache http client builder.
*
* @return the apache http client builder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder();
/**
* Auto refresh token boolean.
*
* @return the boolean
*/
boolean autoRefreshToken();
/**
* Gets access token lock.
*
* @param corpId the corp id
* @return the access token lock
*/
Lock getCorpAccessTokenLock(String corpId, Integer agentId);
void setCorpId(String corpId);
void setAgentId(Integer agentId);
/**
* Gets corp id.
*
* @return the corp id
*/
String getCorpId();
/**
* Gets agent id.
*
* @return the agent id
*/
Integer getAgentId();
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpConfigStorage.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpConfigStorage.java | package me.chanjar.weixin.cp.config;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import java.io.File;
import java.util.concurrent.locks.Lock;
/**
* 微信客户端配置存储.
*
* @author Daniel Qian
*/
public interface WxCpConfigStorage {
/**
* 设置企业微信服务器 baseUrl.
* 默认值是 https://qyapi.weixin.qq.com , 如果使用默认值,则不需要调用 setBaseApiUrl
*
* @param baseUrl 企业微信服务器 Url
*/
void setBaseApiUrl(String baseUrl);
/**
* 读取企业微信 API Url.
* 支持私有化企业微信服务器.
*
* @param path the path
* @return the api url
*/
String getApiUrl(String path);
/**
* Gets access token.
*
* @return the access token
*/
String getAccessToken();
/**
* Gets access token lock.
*
* @return the access token lock
*/
Lock getAccessTokenLock();
/**
* Is access token expired boolean.
*
* @return the boolean
*/
boolean isAccessTokenExpired();
/**
* 强制将access token过期掉.
*/
void expireAccessToken();
/**
* Update access token.
*
* @param accessToken the access token
*/
void updateAccessToken(WxAccessToken accessToken);
/**
* Update access token.
*
* @param accessToken the access token
* @param expiresIn the expires in
*/
void updateAccessToken(String accessToken, int expiresIn);
/**
* Gets jsapi ticket.
*
* @return the jsapi ticket
*/
String getJsapiTicket();
/**
* Gets jsapi ticket lock.
*
* @return the jsapi ticket lock
*/
Lock getJsapiTicketLock();
/**
* Is jsapi ticket expired boolean.
*
* @return the boolean
*/
boolean isJsapiTicketExpired();
/**
* 强制将jsapi ticket过期掉.
*/
void expireJsapiTicket();
/**
* 应该是线程安全的.
*
* @param jsapiTicket the jsapi ticket
* @param expiresInSeconds the expires in seconds
*/
void updateJsapiTicket(String jsapiTicket, int expiresInSeconds);
/**
* Gets agent jsapi ticket.
*
* @return the agent jsapi ticket
*/
String getAgentJsapiTicket();
/**
* Gets agent jsapi ticket lock.
*
* @return the agent jsapi ticket lock
*/
Lock getAgentJsapiTicketLock();
/**
* Is agent jsapi ticket expired boolean.
*
* @return the boolean
*/
boolean isAgentJsapiTicketExpired();
/**
* 强制将jsapi ticket过期掉.
*/
void expireAgentJsapiTicket();
/**
* 应该是线程安全的.
*
* @param jsapiTicket the jsapi ticket
* @param expiresInSeconds the expires in seconds
*/
void updateAgentJsapiTicket(String jsapiTicket, int expiresInSeconds);
/**
* Gets corp id.
*
* @return the corp id
*/
String getCorpId();
/**
* Gets corp secret.
*
* @return the corp secret
*/
String getCorpSecret();
/**
* Gets agent id.
*
* @return the agent id
*/
Integer getAgentId();
/**
* Gets token.
*
* @return the token
*/
String getToken();
/**
* Gets aes key.
*
* @return the aes key
*/
String getAesKey();
/**
* 企微会话存档私钥
*
* @return msg audit pri key
*/
String getMsgAuditPriKey();
/**
* 获取企微会话存档系统库 绝对路径
*
* @return msg audit lib path
*/
String getMsgAuditLibPath();
/**
* Gets expires time.
*
* @return the expires time
*/
long getExpiresTime();
/**
* Gets oauth 2 redirect uri.
*
* @return the oauth 2 redirect uri
*/
String getOauth2redirectUri();
/**
* Gets http proxy host.
*
* @return the http proxy host
*/
String getHttpProxyHost();
/**
* Gets http proxy port.
*
* @return the http proxy port
*/
int getHttpProxyPort();
/**
* Gets http proxy username.
*
* @return the http proxy username
*/
String getHttpProxyUsername();
/**
* Gets http proxy password.
*
* @return the http proxy password
*/
String getHttpProxyPassword();
/**
* Gets tmp dir file.
*
* @return the tmp dir file
*/
File getTmpDirFile();
/**
* http client builder.
*
* @return ApacheHttpClientBuilder apache http client builder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder();
/**
* 是否自动刷新token
*
* @return . boolean
*/
boolean autoRefreshToken();
/**
* 获取群机器人webhook的key
*
* @return key webhook key
*/
String getWebhookKey();
/**
* 获取会话存档的secret
*
* @return msg audit secret
*/
String getMsgAuditSecret();
/**
* 获取会话存档SDK
* 会话存档SDK初始化后有效期为7200秒,无需每次重新初始化
*
* @return sdk id,如果未初始化或已过期返回0
*/
long getMsgAuditSdk();
/**
* 检查会话存档SDK是否已过期
*
* @return true: 已过期, false: 未过期
*/
boolean isMsgAuditSdkExpired();
/**
* 更新会话存档SDK
*
* @param sdk sdk id
* @param expiresInSeconds 过期时间(秒)
*/
void updateMsgAuditSdk(long sdk, int expiresInSeconds);
/**
* 使会话存档SDK过期
*/
void expireMsgAuditSdk();
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpRedisConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpRedisConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import java.io.File;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* <pre>
* 使用说明:本实现仅供参考,并不完整.
* 比如为减少项目依赖,未加入redis分布式锁的实现,如有需要请自行实现。
* </pre>
*
* @author gaigeshen
* @deprecated 不建议使用 ,如有需要,请自行改造实现,加入到自己的项目中并引用
*/
@Deprecated
public class WxCpRedisConfigImpl implements WxCpConfigStorage {
private static final String ACCESS_TOKEN_KEY = "WX_CP_ACCESS_TOKEN";
private static final String ACCESS_TOKEN_EXPIRES_TIME_KEY = "WX_CP_ACCESS_TOKEN_EXPIRES_TIME";
private static final String JS_API_TICKET_KEY = "WX_CP_JS_API_TICKET";
private static final String JS_API_TICKET_EXPIRES_TIME_KEY = "WX_CP_JS_API_TICKET_EXPIRES_TIME";
private static final String AGENT_JSAPI_TICKET_KEY = "WX_CP_AGENT_%s_JSAPI_TICKET";
private static final String AGENT_JSAPI_TICKET_EXPIRES_TIME_KEY = "WX_CP_AGENT_%s_JSAPI_TICKET_EXPIRES_TIME";
private final JedisPool jedisPool;
/**
* The Base api url.
*/
protected volatile String baseApiUrl;
private volatile String corpId;
private volatile String corpSecret;
private volatile String token;
private volatile String aesKey;
private volatile Integer agentId;
private volatile String msgAuditPriKey;
private volatile String msgAuditLibPath;
private volatile String oauth2redirectUri;
private volatile String httpProxyHost;
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
private volatile File tmpDirFile;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private volatile String webhookKey;
/**
* 会话存档SDK及其过期时间(SDK是本地JVM变量,不适合存储到Redis)
*/
private volatile long msgAuditSdk;
private volatile long msgAuditSdkExpiresTime;
/**
* Instantiates a new Wx cp redis config.
*
* @param jedisPool the jedis pool
*/
public WxCpRedisConfigImpl(JedisPool jedisPool) {
this.jedisPool = jedisPool;
}
/**
* Instantiates a new Wx cp redis config.
*
* @param host the host
* @param port the port
*/
public WxCpRedisConfigImpl(String host, int port) {
jedisPool = new JedisPool(host, port);
}
/**
* Instantiates a new Wx cp redis config.
*
* @param poolConfig the pool config
* @param host the host
* @param port the port
*/
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port) {
jedisPool = new JedisPool(poolConfig, host, port);
}
/**
* Instantiates a new Wx cp redis config.
*
* @param poolConfig the pool config
* @param host the host
* @param port the port
* @param timeout the timeout
* @param password the password
*/
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port, int timeout, String password) {
jedisPool = new JedisPool(poolConfig, host, port, timeout, password);
}
/**
* Instantiates a new Wx cp redis config.
*
* @param poolConfig the pool config
* @param host the host
* @param port the port
* @param timeout the timeout
* @param password the password
* @param database the database
*/
public WxCpRedisConfigImpl(JedisPoolConfig poolConfig, String host, int port, int timeout, String password,
int database) {
jedisPool = new JedisPool(poolConfig, host, port, timeout, password, database);
}
@Override
public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl;
}
@Override
public String getApiUrl(String path) {
if (baseApiUrl == null) {
baseApiUrl = WxCpApiPathConsts.DEFAULT_CP_BASE_URL;
}
return baseApiUrl + path;
}
/**
* This method will be destroy jedis pool
*/
public void destroy() {
this.jedisPool.destroy();
}
@Override
public String getAccessToken() {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.get(ACCESS_TOKEN_KEY);
}
}
@Override
public Lock getAccessTokenLock() {
return new ReentrantLock();
}
@Override
public boolean isAccessTokenExpired() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
return System.currentTimeMillis() > Long.parseLong(expiresTimeStr);
}
return true;
}
}
@Override
public void expireAccessToken() {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(ACCESS_TOKEN_EXPIRES_TIME_KEY, "0");
}
}
@Override
public synchronized void updateAccessToken(WxAccessToken accessToken) {
this.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
}
@Override
public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(ACCESS_TOKEN_KEY, accessToken);
jedis.set(ACCESS_TOKEN_EXPIRES_TIME_KEY,
(System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L) + "");
}
}
@Override
public String getJsapiTicket() {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.get(JS_API_TICKET_KEY);
}
}
@Override
public Lock getJsapiTicketLock() {
return new ReentrantLock();
}
@Override
public boolean isJsapiTicketExpired() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(JS_API_TICKET_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
long expiresTime = Long.parseLong(expiresTimeStr);
return System.currentTimeMillis() > expiresTime;
}
return true;
}
}
@Override
public void expireJsapiTicket() {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(JS_API_TICKET_EXPIRES_TIME_KEY, "0");
}
}
@Override
public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(JS_API_TICKET_KEY, jsapiTicket);
jedis.set(JS_API_TICKET_EXPIRES_TIME_KEY,
(System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L + ""));
}
}
@Override
public String getAgentJsapiTicket() {
try (Jedis jedis = this.jedisPool.getResource()) {
return jedis.get(String.format(AGENT_JSAPI_TICKET_KEY, agentId));
}
}
@Override
public Lock getAgentJsapiTicketLock() {
return new ReentrantLock();
}
@Override
public boolean isAgentJsapiTicketExpired() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(String.format(AGENT_JSAPI_TICKET_EXPIRES_TIME_KEY, agentId));
if (expiresTimeStr != null) {
return System.currentTimeMillis() > Long.parseLong(expiresTimeStr);
}
return true;
}
}
@Override
public void expireAgentJsapiTicket() {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(String.format(AGENT_JSAPI_TICKET_EXPIRES_TIME_KEY, agentId), "0");
}
}
@Override
public void updateAgentJsapiTicket(String jsapiTicket, int expiresInSeconds) {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.set(String.format(AGENT_JSAPI_TICKET_KEY, agentId), jsapiTicket);
jedis.set(String.format(AGENT_JSAPI_TICKET_EXPIRES_TIME_KEY, agentId),
(System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L + ""));
}
}
@Override
public String getCorpId() {
return this.corpId;
}
/**
* Sets corp id.
*
* @param corpId the corp id
*/
public void setCorpId(String corpId) {
this.corpId = corpId;
}
@Override
public String getCorpSecret() {
return this.corpSecret;
}
/**
* Sets corp secret.
*
* @param corpSecret the corp secret
*/
public void setCorpSecret(String corpSecret) {
this.corpSecret = corpSecret;
}
@Override
public Integer getAgentId() {
return this.agentId;
}
/**
* Sets agent id.
*
* @param agentId the agent id
*/
public void setAgentId(Integer agentId) {
this.agentId = agentId;
}
@Override
public String getToken() {
return this.token;
}
/**
* Sets token.
*
* @param token the token
*/
public void setToken(String token) {
this.token = token;
}
@Override
public String getAesKey() {
return this.aesKey;
}
@Override
public String getMsgAuditPriKey() {
return this.msgAuditPriKey;
}
@Override
public String getMsgAuditLibPath() {
return this.msgAuditLibPath;
}
/**
* Sets aes key.
*
* @param aesKey the aes key
*/
public void setAesKey(String aesKey) {
this.aesKey = aesKey;
}
@Override
public long getExpiresTime() {
try (Jedis jedis = this.jedisPool.getResource()) {
String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY);
if (expiresTimeStr != null) {
return Long.parseLong(expiresTimeStr);
}
return 0L;
}
}
@Override
public String getOauth2redirectUri() {
return this.oauth2redirectUri;
}
/**
* Sets oauth 2 redirect uri.
*
* @param oauth2redirectUri the oauth 2 redirect uri
*/
public void setOauth2redirectUri(String oauth2redirectUri) {
this.oauth2redirectUri = oauth2redirectUri;
}
@Override
public String getHttpProxyHost() {
return this.httpProxyHost;
}
/**
* Sets http proxy host.
*
* @param httpProxyHost the http proxy host
*/
public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost;
}
@Override
public int getHttpProxyPort() {
return this.httpProxyPort;
}
/**
* Sets http proxy port.
*
* @param httpProxyPort the http proxy port
*/
public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort;
}
@Override
public String getHttpProxyUsername() {
return this.httpProxyUsername;
}
// ============================ Setters below
/**
* Sets http proxy username.
*
* @param httpProxyUsername the http proxy username
*/
public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername;
}
@Override
public String getHttpProxyPassword() {
return this.httpProxyPassword;
}
/**
* Sets http proxy password.
*
* @param httpProxyPassword the http proxy password
*/
public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword;
}
@Override
public File getTmpDirFile() {
return this.tmpDirFile;
}
/**
* Sets tmp dir file.
*
* @param tmpDirFile the tmp dir file
*/
public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile;
}
@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}
/**
* Sets apache http client builder.
*
* @param apacheHttpClientBuilder the apache http client builder
*/
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
@Override
public boolean autoRefreshToken() {
return true;
}
@Override
public String getWebhookKey() {
return this.webhookKey;
}
@Override
public String getMsgAuditSecret() {
return null;
}
@Override
public long getMsgAuditSdk() {
return this.msgAuditSdk;
}
@Override
public boolean isMsgAuditSdkExpired() {
return System.currentTimeMillis() > this.msgAuditSdkExpiresTime;
}
@Override
public synchronized void updateMsgAuditSdk(long sdk, int expiresInSeconds) {
this.msgAuditSdk = sdk;
// 预留200秒的时间
this.msgAuditSdkExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
}
@Override
public void expireMsgAuditSdk() {
this.msgAuditSdkExpiresTime = 0;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpCorpGroupRedissonConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpCorpGroupRedissonConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.Builder;
import lombok.NonNull;
import lombok.Setter;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.redis.WxRedisOps;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.config.WxCpCorpGroupConfigStorage;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
/**
* 企业微信企业互联各种固定、授权配置的Redisson存储实现
*
* @author libo Email: 422423229@qq.com
* @since 1/3/2023 10:48 AM
*/
@Builder
public class WxCpCorpGroupRedissonConfigImpl implements WxCpCorpGroupConfigStorage, Serializable {
private static final long serialVersionUID = 1269450173683931930L;
private final transient Map<String, Lock> corpAccessTokenLocker = new ConcurrentHashMap<>();
/**
* The constant LOCK_KEY.
*/
protected static final String LOCK_KEY = "wechat_cg_lock:";
/**
* The constant LOCKER_CORP_ACCESS_TOKEN.
*/
protected static final String LOCKER_CORP_ACCESS_TOKEN = "corpAccessTokenLock";
/**
* The constant CG_ACCESS_TOKEN_KEY.
*/
protected static final String CG_ACCESS_TOKEN_KEY = "wechat_cg_access_token_key:";
@NonNull
private final WxRedisOps wxRedisOps;
/**
* redis里面key的统一前缀
*/
@Setter
private String keyPrefix = "";
private volatile String httpProxyHost;
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private volatile String baseApiUrl;
/**
* 微信企业号 corpId
*/
private volatile String corpId;
/**
* 微信企业号应用 ID
*/
private volatile Integer agentId;
@Override
public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl;
}
@Override
public String getApiUrl(String path) {
if (baseApiUrl == null) {
baseApiUrl = "https://qyapi.weixin.qq.com";
}
return baseApiUrl + path;
}
@Override
public String getCorpId() {
return corpId;
}
@Override
public void setCorpId(String corpId) {
this.corpId = corpId;
}
@Override
public Integer getAgentId() {
return agentId;
}
@Override
public void setAgentId(Integer agentId) {
this.agentId = agentId;
}
@Override
public void updateCorpAccessToken(String corpId, Integer agentId, String corpAccessToken, int expiresInSeconds) {
wxRedisOps.setValue(generateAccessTokenKey(corpId, agentId), corpAccessToken, expiresInSeconds, TimeUnit.SECONDS);
}
@Override
public String getCorpAccessToken(String corpId, Integer agentId) {
return wxRedisOps.getValue(generateAccessTokenKey(corpId, agentId));
}
@Override
public WxAccessToken getCorpAccessTokenEntity(String corpId, Integer agentId) {
String key = generateAccessTokenKey(corpId, agentId);
String accessToken = wxRedisOps.getValue(key);
Long expire = wxRedisOps.getExpire(key);
if (StringUtils.isBlank(accessToken) || expire == null || expire == 0 || expire == -2) {
return new WxAccessToken();
}
WxAccessToken accessTokenEntity = new WxAccessToken();
accessTokenEntity.setAccessToken(accessToken);
accessTokenEntity.setExpiresIn(Math.max(Math.toIntExact(expire), 0));
return accessTokenEntity;
}
@Override
public boolean isCorpAccessTokenExpired(String corpId, Integer agentId) {
String key = generateAccessTokenKey(corpId, agentId);
return wxRedisOps.getExpire(key) == 0L || wxRedisOps.getExpire(key) == -2;
}
@Override
public void expireCorpAccessToken(String corpId, Integer agentId) {
wxRedisOps.expire(generateAccessTokenKey(corpId, agentId), 0, TimeUnit.SECONDS);
}
@Override
public String getHttpProxyHost() {
return this.httpProxyHost;
}
/**
* Sets http proxy host.
*
* @param httpProxyHost the http proxy host
*/
public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost;
}
@Override
public int getHttpProxyPort() {
return this.httpProxyPort;
}
/**
* Sets http proxy port.
*
* @param httpProxyPort the http proxy port
*/
public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort;
}
@Override
public String getHttpProxyUsername() {
return this.httpProxyUsername;
}
/**
* Sets http proxy username.
*
* @param httpProxyUsername the http proxy username
*/
public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername;
}
@Override
public String getHttpProxyPassword() {
return this.httpProxyPassword;
}
/**
* Sets http proxy password.
*
* @param httpProxyPassword the http proxy password
*/
public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword;
}
@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}
/**
* Sets apache http client builder.
*
* @param apacheHttpClientBuilder the apache http client builder
*/
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
@Override
public boolean autoRefreshToken() {
return true;
}
@Override
public Lock getCorpAccessTokenLock(String corpId, Integer agentId) {
return this.getLockByKey(String.join(":", corpId, String.valueOf(agentId), LOCKER_CORP_ACCESS_TOKEN));
}
private String generateAccessTokenKey(String corpId, Integer agentId) {
return String.join(":", keyPrefix, CG_ACCESS_TOKEN_KEY, corpId, String.valueOf(agentId));
}
private Lock getLockByKey(String key) {
return this.wxRedisOps.getLock(String.join(":", keyPrefix, LOCK_KEY, key));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpJedisConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpJedisConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.NonNull;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.util.Pool;
/**
* 基于 jdis 的实现
*
* @author yl
* created on 2023/04/23
*/
public class WxCpJedisConfigImpl extends AbstractWxCpInRedisConfigImpl {
private static final long serialVersionUID = -1869372247414407433L;
public WxCpJedisConfigImpl(Pool<Jedis> jedisPool) {
this(jedisPool, null);
}
public WxCpJedisConfigImpl(@NonNull Pool<Jedis> jedisPool, String keyPrefix) {
super(new JedisWxRedisOps(jedisPool), keyPrefix);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpRedisTemplateConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpRedisTemplateConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.NonNull;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import org.springframework.data.redis.core.StringRedisTemplate;
/**
* 基于 RedisTemplate 的实现
*
* @author yl
* created on 2023/04/23
*/
public class WxCpRedisTemplateConfigImpl extends AbstractWxCpInRedisConfigImpl {
private static final long serialVersionUID = -1660004125413310620L;
public WxCpRedisTemplateConfigImpl(@NonNull StringRedisTemplate stringRedisTemplate) {
this(stringRedisTemplate, null);
}
public WxCpRedisTemplateConfigImpl(@NonNull StringRedisTemplate stringRedisTemplate, String keyPrefix) {
super(new RedisTemplateWxRedisOps(stringRedisTemplate), keyPrefix);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpCorpGroupDefaultConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpCorpGroupDefaultConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.config.WxCpCorpGroupConfigStorage;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化.
*
* @author libo
*/
public class WxCpCorpGroupDefaultConfigImpl implements WxCpCorpGroupConfigStorage, Serializable {
private static final long serialVersionUID = -8392908346536154435L;
private final transient Map<String, Lock> corpAccessTokenLocker = new ConcurrentHashMap<>();
private final Map<String, String> corpAccessTokenMap = new HashMap<>();
private final Map<String, Long> corpAccessTokenExpireTimeMap = new HashMap<>();
private volatile String httpProxyHost;
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private volatile String baseApiUrl;
/**
* 微信企业号 corpId
*/
private volatile String corpId;
/**
* 微信企业号应用 ID
*/
private volatile Integer agentId;
@Override
public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl;
}
@Override
public String getApiUrl(String path) {
if (baseApiUrl == null) {
baseApiUrl = "https://qyapi.weixin.qq.com";
}
return baseApiUrl + path;
}
@Override
public String getCorpId() {
return corpId;
}
@Override
public void setCorpId(String corpId) {
this.corpId = corpId;
}
@Override
public Integer getAgentId() {
return agentId;
}
@Override
public void setAgentId(Integer agentId) {
this.agentId = agentId;
}
@Override
public void updateCorpAccessToken(String corpId, Integer agentId, String corpAccessToken, int expiresInSeconds) {
String key = generateAccessTokenKey(corpId, agentId);
corpAccessTokenMap.put(key, corpAccessToken);
//预留200秒的时间
corpAccessTokenExpireTimeMap.put(key, System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L);
}
@Override
public String getCorpAccessToken(String corpId, Integer agentId) {
return this.corpAccessTokenMap.get(generateAccessTokenKey(corpId, agentId));
}
@Override
public WxAccessToken getCorpAccessTokenEntity(String corpId, Integer agentId) {
String key = generateAccessTokenKey(corpId, agentId);
String accessToken = corpAccessTokenMap.getOrDefault(key, StringUtils.EMPTY);
Long expire = corpAccessTokenExpireTimeMap.getOrDefault(key, 0L);
WxAccessToken accessTokenEntity = new WxAccessToken();
accessTokenEntity.setAccessToken(accessToken);
accessTokenEntity.setExpiresIn((int) ((expire - System.currentTimeMillis()) / 1000 + 200));
return accessTokenEntity;
}
@Override
public boolean isCorpAccessTokenExpired(String corpId, Integer agentId) {
//不存在或者过期
String key = generateAccessTokenKey(corpId, agentId);
return corpAccessTokenExpireTimeMap.get(key) == null
|| System.currentTimeMillis() > corpAccessTokenExpireTimeMap.get(key);
}
@Override
public void expireCorpAccessToken(String corpId, Integer agentId) {
String key = generateAccessTokenKey(corpId, agentId);
corpAccessTokenMap.remove(key);
corpAccessTokenExpireTimeMap.remove(key);
}
@Override
public String getHttpProxyHost() {
return this.httpProxyHost;
}
/**
* Sets http proxy host.
*
* @param httpProxyHost the http proxy host
*/
public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost;
}
@Override
public int getHttpProxyPort() {
return this.httpProxyPort;
}
/**
* Sets http proxy port.
*
* @param httpProxyPort the http proxy port
*/
public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort;
}
@Override
public String getHttpProxyUsername() {
return this.httpProxyUsername;
}
/**
* Sets http proxy username.
*
* @param httpProxyUsername the http proxy username
*/
public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername;
}
@Override
public String getHttpProxyPassword() {
return this.httpProxyPassword;
}
/**
* Sets http proxy password.
*
* @param httpProxyPassword the http proxy password
*/
public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword;
}
@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}
/**
* Sets apache http client builder.
*
* @param apacheHttpClientBuilder the apache http client builder
*/
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
@Override
public boolean autoRefreshToken() {
return true;
}
@Override
public Lock getCorpAccessTokenLock(String corpId, Integer agentId) {
return this.corpAccessTokenLocker
.computeIfAbsent(generateAccessTokenKey(corpId, agentId), key -> new ReentrantLock());
}
private String generateAccessTokenKey(String corpId, Integer agentId) {
return String.join(":", this.corpId, String.valueOf(this.agentId), corpId, String.valueOf(agentId));
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/AbstractWxCpInRedisConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/AbstractWxCpInRedisConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.NonNull;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.redis.WxRedisOps;
import org.apache.commons.lang3.StringUtils;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
/**
* @author yl
* created on 2023/04/23
*/
public abstract class AbstractWxCpInRedisConfigImpl extends WxCpDefaultConfigImpl {
private static final long serialVersionUID = 7157341535439380615L;
/**
* The constant LOCK_KEY.
*/
protected static final String LOCK_KEY = "wechat_cp_lock:";
/**
* The constant CP_ACCESS_TOKEN_KEY.
*/
protected static final String CP_ACCESS_TOKEN_KEY = "wechat_cp_access_token_key:";
/**
* The constant CP_JSAPI_TICKET_KEY.
*/
protected static final String CP_JSAPI_TICKET_KEY = "wechat_cp_jsapi_ticket_key:";
/**
* The constant CP_AGENT_JSAPI_TICKET_KEY.
*/
protected static final String CP_AGENT_JSAPI_TICKET_KEY = "wechat_cp_agent_jsapi_ticket_key:";
/**
* redis 存储的 key 的前缀,可为空
*/
protected String keyPrefix;
/**
* The Access token key.
*/
protected String accessTokenKey;
/**
* The Jsapi ticket key.
*/
protected String jsapiTicketKey;
/**
* The Agent jsapi ticket key.
*/
protected String agentJsapiTicketKey;
/**
* The Lock key.
*/
protected String lockKey;
private final WxRedisOps redisOps;
/**
* Instantiates a new Wx cp redis config.
*
* @param redisOps the redis ops
* @param keyPrefix the key prefix
*/
public AbstractWxCpInRedisConfigImpl(@NonNull WxRedisOps redisOps, String keyPrefix) {
this.redisOps = redisOps;
this.keyPrefix = keyPrefix;
}
/**
* 设置企业微信自研应用ID(整数),同时初始化相关的redis key,注意要先调用setCorpId,再调用setAgentId
*
* @param agentId 应用 agentId
*/
@Override
public void setAgentId(Integer agentId) {
super.setAgentId(agentId);
String ukey;
if (agentId != null) {
ukey = getCorpId().concat(":").concat(String.valueOf(agentId));
} else {
ukey = getCorpId();
}
String prefix = StringUtils.isBlank(keyPrefix) ? "" :
(StringUtils.endsWith(keyPrefix, ":") ? keyPrefix : (keyPrefix + ":"));
lockKey = prefix + LOCK_KEY.concat(ukey);
accessTokenKey = prefix + CP_ACCESS_TOKEN_KEY.concat(ukey);
jsapiTicketKey = prefix + CP_JSAPI_TICKET_KEY.concat(ukey);
agentJsapiTicketKey = prefix + CP_AGENT_JSAPI_TICKET_KEY.concat(ukey);
}
/**
* Gets lock by key.
*
* @param key the key
* @return the lock by key
*/
protected Lock getLockByKey(String key) {
return redisOps.getLock(key);
}
@Override
public Lock getAccessTokenLock() {
return getLockByKey(this.lockKey.concat(":").concat("accessToken"));
}
@Override
public Lock getAgentJsapiTicketLock() {
return getLockByKey(this.lockKey.concat(":").concat("agentJsapiTicket"));
}
@Override
public Lock getJsapiTicketLock() {
return getLockByKey(this.lockKey.concat(":").concat("jsapiTicket"));
}
@Override
public String getAccessToken() {
return redisOps.getValue(this.accessTokenKey);
}
@Override
public boolean isAccessTokenExpired() {
Long expire = redisOps.getExpire(this.accessTokenKey);
return expire == null || expire < 2;
}
@Override
public void updateAccessToken(WxAccessToken accessToken) {
redisOps.setValue(this.accessTokenKey, accessToken.getAccessToken(), accessToken.getExpiresIn(), TimeUnit.SECONDS);
}
@Override
public void updateAccessToken(String accessToken, int expiresInSeconds) {
redisOps.setValue(this.accessTokenKey, accessToken, expiresInSeconds, TimeUnit.SECONDS);
}
@Override
public void expireAccessToken() {
redisOps.expire(this.accessTokenKey, 0, TimeUnit.SECONDS);
}
@Override
public String getJsapiTicket() {
return redisOps.getValue(this.jsapiTicketKey);
}
@Override
public boolean isJsapiTicketExpired() {
Long expire = redisOps.getExpire(this.jsapiTicketKey);
return expire == null || expire < 2;
}
@Override
public void expireJsapiTicket() {
redisOps.expire(this.jsapiTicketKey, 0, TimeUnit.SECONDS);
}
@Override
public void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) {
redisOps.setValue(this.jsapiTicketKey, jsapiTicket, expiresInSeconds, TimeUnit.SECONDS);
}
@Override
public void expireAgentJsapiTicket() {
redisOps.expire(this.agentJsapiTicketKey, 0, TimeUnit.SECONDS);
}
@Override
public void updateAgentJsapiTicket(String agentJsapiTicket, int expiresInSeconds) {
redisOps.setValue(this.agentJsapiTicketKey, agentJsapiTicket, expiresInSeconds, TimeUnit.SECONDS);
}
@Override
public String getAgentJsapiTicket() {
return redisOps.getValue(this.agentJsapiTicketKey);
}
@Override
public boolean isAgentJsapiTicketExpired() {
Long expire = redisOps.getExpire(this.agentJsapiTicketKey);
return expire == null || expire < 2;
}
@Override
public String toString() {
return "AbstractWxCpInRedisConfigImpl{" +
"corpId='" + getCorpId() + '\'' +
", agentId=" + getAgentId() +
", keyPrefix='" + keyPrefix + '\'' +
", accessTokenKey='" + accessTokenKey + '\'' +
", jsapiTicketKey='" + jsapiTicketKey + '\'' +
", agentJsapiTicketKey='" + agentJsapiTicketKey + '\'' +
", lockKey='" + lockKey + '\'' +
'}';
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpRedissonConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpRedissonConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.NonNull;
import me.chanjar.weixin.common.redis.RedissonWxRedisOps;
import org.redisson.api.RedissonClient;
/**
* 基于Redisson的实现
*
* @author yuanqixun created on 2020 /5/13
* @author yl
*/
public class WxCpRedissonConfigImpl extends AbstractWxCpInRedisConfigImpl {
private static final long serialVersionUID = -5674792341070783967L;
public WxCpRedissonConfigImpl(@NonNull RedissonClient redissonClient) {
this(redissonClient, null);
}
public WxCpRedissonConfigImpl(@NonNull RedissonClient redissonClient, String keyPrefix) {
super(new RedissonWxRedisOps(redissonClient), keyPrefix);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpJedisConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpJedisConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.NonNull;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.util.Pool;
/**
* 基于 jedis 的实现
*
* @author yl
* created on 2023/04/23
*/
public class WxCpTpJedisConfigImpl extends AbstractWxCpTpInRedisConfigImpl {
private static final long serialVersionUID = -1869372247414407433L;
public WxCpTpJedisConfigImpl(Pool<Jedis> jedisPool) {
this(jedisPool, null);
}
public WxCpTpJedisConfigImpl(@NonNull Pool<Jedis> jedisPool, String keyPrefix) {
super(new JedisWxRedisOps(jedisPool), keyPrefix);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/AbstractWxCpTpInRedisConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/AbstractWxCpTpInRedisConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.Builder;
import lombok.NonNull;
import lombok.Setter;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.redis.RedissonWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RedissonClient;
import java.io.File;
import java.io.Serializable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
/**
* 企业微信各种固定、授权配置的Redisson存储实现
*/
public abstract class AbstractWxCpTpInRedisConfigImpl extends WxCpTpDefaultConfigImpl implements Serializable {
private static final long serialVersionUID = -5385639031981770319L;
public AbstractWxCpTpInRedisConfigImpl(@NonNull WxRedisOps wxRedisOps) {
this(wxRedisOps, null);
}
public AbstractWxCpTpInRedisConfigImpl(@NonNull WxRedisOps wxRedisOps, String keyPrefix) {
this.wxRedisOps = wxRedisOps;
this.keyPrefix = keyPrefix;
}
/**
* The constant LOCK_KEY.
*/
// lock key
protected static final String LOCK_KEY = "wechat_tp_lock:";
/**
* The constant LOCKER_PROVIDER_ACCESS_TOKEN.
*/
protected static final String LOCKER_PROVIDER_ACCESS_TOKEN = "providerAccessTokenLock";
/**
* The constant LOCKER_SUITE_ACCESS_TOKEN.
*/
protected static final String LOCKER_SUITE_ACCESS_TOKEN = "suiteAccessTokenLock";
/**
* The constant LOCKER_ACCESS_TOKEN.
*/
protected static final String LOCKER_ACCESS_TOKEN = "accessTokenLock";
/**
* The constant LOCKER_CORP_JSAPI_TICKET.
*/
protected static final String LOCKER_CORP_JSAPI_TICKET = "corpJsapiTicketLock";
/**
* The constant LOCKER_SUITE_JSAPI_TICKET.
*/
protected static final String LOCKER_SUITE_JSAPI_TICKET = "suiteJsapiTicketLock";
@NonNull
private final WxRedisOps wxRedisOps;
private final String suiteAccessTokenKey = ":suiteAccessTokenKey:";
private final String suiteTicketKey = ":suiteTicketKey:";
private final String accessTokenKey = ":accessTokenKey:";
private final String authCorpJsApiTicketKey = ":authCorpJsApiTicketKey:";
private final String authSuiteJsApiTicketKey = ":authSuiteJsApiTicketKey:";
private final String providerTokenKey = ":providerTokenKey:";
/**
* redis里面key的统一前缀
*/
@Setter
private String keyPrefix = "";
private volatile String baseApiUrl;
private volatile String httpProxyHost;
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private volatile File tmpDirFile;
@Override
public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl;
}
@Override
public String getApiUrl(String path) {
if (baseApiUrl == null) {
baseApiUrl = "https://qyapi.weixin.qq.com";
}
return baseApiUrl + path;
}
/**
* 第三方应用的suite access token相关
*/
@Override
public String getSuiteAccessToken() {
return wxRedisOps.getValue(keyWithPrefix(suiteAccessTokenKey));
}
@Override
public WxAccessToken getSuiteAccessTokenEntity() {
String suiteAccessToken = wxRedisOps.getValue(keyWithPrefix(suiteAccessTokenKey));
Long expireIn = wxRedisOps.getExpire(keyWithPrefix(suiteAccessTokenKey));
if (StringUtils.isBlank(suiteAccessToken) || expireIn == null || expireIn == 0 || expireIn == -2) {
return new WxAccessToken();
}
WxAccessToken suiteAccessTokenEntity = new WxAccessToken();
suiteAccessTokenEntity.setAccessToken(suiteAccessToken);
suiteAccessTokenEntity.setExpiresIn(Math.max(Math.toIntExact(expireIn), 0));
return suiteAccessTokenEntity;
}
@Override
public boolean isSuiteAccessTokenExpired() {
//remain time to live in seconds, or key not exist
return wxRedisOps.getExpire(keyWithPrefix(suiteAccessTokenKey)) == 0L || wxRedisOps.getExpire(keyWithPrefix(suiteAccessTokenKey)) == -2;
}
@Override
public void expireSuiteAccessToken() {
wxRedisOps.expire(keyWithPrefix(suiteAccessTokenKey), 0, TimeUnit.SECONDS);
}
@Override
public void updateSuiteAccessToken(WxAccessToken suiteAccessToken) {
updateSuiteAccessToken(suiteAccessToken.getAccessToken(), suiteAccessToken.getExpiresIn());
}
@Override
public void updateSuiteAccessToken(String suiteAccessToken, int expiresInSeconds) {
wxRedisOps.setValue(keyWithPrefix(suiteAccessTokenKey), suiteAccessToken, expiresInSeconds, TimeUnit.SECONDS);
}
/**
* 第三方应用的suite ticket相关
*/
@Override
public String getSuiteTicket() {
return wxRedisOps.getValue(keyWithPrefix(suiteTicketKey));
}
@Override
public boolean isSuiteTicketExpired() {
//remain time to live in seconds, or key not exist
return wxRedisOps.getExpire(keyWithPrefix(suiteTicketKey)) == 0L || wxRedisOps.getExpire(keyWithPrefix(suiteTicketKey)) == -2;
}
@Override
public void expireSuiteTicket() {
wxRedisOps.expire(keyWithPrefix(suiteTicketKey), 0, TimeUnit.SECONDS);
}
@Override
public void updateSuiteTicket(String suiteTicket, int expiresInSeconds) {
wxRedisOps.setValue(keyWithPrefix(suiteTicketKey), suiteTicket, expiresInSeconds, TimeUnit.SECONDS);
}
/**
* 第三方应用的其他配置,来自于企微配置
*/
@Override
public String getSuiteId() {
return suiteId;
}
@Override
public String getSuiteSecret() {
return suiteSecret;
}
// 第三方应用的token,用来检查应用的签名
@Override
public String getToken() {
return token;
}
//第三方应用的EncodingAESKey,用来检查签名
@Override
public String getEncodingAESKey() {
return encodingAESKey;
}
/**
* 企微服务商企业ID & 企业secret, 来自于企微配置
*/
@Override
public String getCorpId() {
return corpId;
}
@Override
public String getProviderSecret() {
return providerSecret;
}
@Override
public void setProviderSecret(String providerSecret) {
this.providerSecret = providerSecret;
}
/**
* 授权企业的access token相关
*/
@Override
public String getAccessToken(String authCorpId) {
return wxRedisOps.getValue(keyWithPrefix(authCorpId) + accessTokenKey);
}
@Override
public WxAccessToken getAccessTokenEntity(String authCorpId) {
String accessToken = wxRedisOps.getValue(keyWithPrefix(authCorpId) + accessTokenKey);
Long expire = wxRedisOps.getExpire(keyWithPrefix(authCorpId) + accessTokenKey);
if (StringUtils.isBlank(accessToken) || expire == null || expire == 0 || expire == -2) {
return new WxAccessToken();
}
WxAccessToken accessTokenEntity = new WxAccessToken();
accessTokenEntity.setAccessToken(accessToken);
accessTokenEntity.setExpiresIn((int) ((expire - System.currentTimeMillis()) / 1000 + 200));
return accessTokenEntity;
}
@Override
public boolean isAccessTokenExpired(String authCorpId) {
//没有设置或者TTL为0,都是过期
return wxRedisOps.getExpire(keyWithPrefix(authCorpId) + accessTokenKey) == 0L
|| wxRedisOps.getExpire(keyWithPrefix(authCorpId) + accessTokenKey) == -2;
}
@Override
public void expireAccessToken(String authCorpId) {
wxRedisOps.expire(keyWithPrefix(authCorpId) + accessTokenKey, 0, TimeUnit.SECONDS);
}
@Override
public void updateAccessToken(String authCorpId, String accessToken, int expiredInSeconds) {
wxRedisOps.setValue(keyWithPrefix(authCorpId) + accessTokenKey, accessToken, expiredInSeconds, TimeUnit.SECONDS);
}
/**
* 授权企业的js api ticket相关
*/
@Override
public String getAuthCorpJsApiTicket(String authCorpId) {
return wxRedisOps.getValue(keyWithPrefix(authCorpId) + authCorpJsApiTicketKey);
}
@Override
public boolean isAuthCorpJsApiTicketExpired(String authCorpId) {
//没有设置或TTL为0,都是过期
return wxRedisOps.getExpire(keyWithPrefix(authCorpId) + authCorpJsApiTicketKey) == 0L
|| wxRedisOps.getExpire(keyWithPrefix(authCorpId) + authCorpJsApiTicketKey) == -2;
}
@Override
public void expireAuthCorpJsApiTicket(String authCorpId) {
wxRedisOps.expire(keyWithPrefix(authCorpId) + authCorpJsApiTicketKey, 0, TimeUnit.SECONDS);
}
@Override
public void updateAuthCorpJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds) {
wxRedisOps.setValue(keyWithPrefix(authCorpId) + authCorpJsApiTicketKey, jsApiTicket, expiredInSeconds,
TimeUnit.SECONDS);
}
/**
* 授权企业的第三方应用js api ticket相关
*/
@Override
public String getAuthSuiteJsApiTicket(String authCorpId) {
return wxRedisOps.getValue(keyWithPrefix(authCorpId) + authSuiteJsApiTicketKey);
}
@Override
public boolean isAuthSuiteJsApiTicketExpired(String authCorpId) {
//没有设置或者TTL为0,都是过期
return wxRedisOps.getExpire(keyWithPrefix(authCorpId) + authSuiteJsApiTicketKey) == 0L
|| wxRedisOps.getExpire(keyWithPrefix(authCorpId) + authSuiteJsApiTicketKey) == -2;
}
@Override
public void expireAuthSuiteJsApiTicket(String authCorpId) {
wxRedisOps.expire(keyWithPrefix(authCorpId) + authSuiteJsApiTicketKey, 0, TimeUnit.SECONDS);
}
@Override
public void updateAuthSuiteJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds) {
wxRedisOps.setValue(keyWithPrefix(authCorpId) + authSuiteJsApiTicketKey, jsApiTicket, expiredInSeconds,
TimeUnit.SECONDS);
}
@Override
public boolean isProviderTokenExpired() {
//remain time to live in seconds, or key not exist
return wxRedisOps.getExpire(providerKeyWithPrefix(providerTokenKey)) == 0L || wxRedisOps.getExpire(providerKeyWithPrefix(providerTokenKey)) == -2;
}
@Override
public void updateProviderToken(String providerToken, int expiredInSeconds) {
wxRedisOps.setValue(providerKeyWithPrefix(providerTokenKey), providerToken, expiredInSeconds, TimeUnit.SECONDS);
}
@Override
public String getProviderToken() {
return wxRedisOps.getValue(providerKeyWithPrefix(providerTokenKey));
}
@Override
public WxCpProviderToken getProviderTokenEntity() {
String providerToken = wxRedisOps.getValue(providerKeyWithPrefix(providerTokenKey));
Long expire = wxRedisOps.getExpire(providerKeyWithPrefix(providerTokenKey));
if (StringUtils.isBlank(providerToken) || expire == null || expire == 0 || expire == -2) {
return new WxCpProviderToken();
}
WxCpProviderToken wxCpProviderToken = new WxCpProviderToken();
wxCpProviderToken.setProviderAccessToken(providerToken);
wxCpProviderToken.setExpiresIn(Math.max(Math.toIntExact(expire), 0));
return wxCpProviderToken;
}
@Override
public void expireProviderToken() {
wxRedisOps.expire(providerKeyWithPrefix(providerTokenKey), 0, TimeUnit.SECONDS);
}
/**
* 网络代理相关
*/
@Override
public String getHttpProxyHost() {
return this.httpProxyHost;
}
@Override
public int getHttpProxyPort() {
return this.httpProxyPort;
}
@Override
public String getHttpProxyUsername() {
return this.httpProxyUsername;
}
@Override
public String getHttpProxyPassword() {
return this.httpProxyPassword;
}
@Override
public File getTmpDirFile() {
return tmpDirFile;
}
@Override
public Lock getProviderAccessTokenLock() {
return getProviderLockByKey(String.join(":", this.corpId, LOCKER_PROVIDER_ACCESS_TOKEN));
}
@Override
public Lock getSuiteAccessTokenLock() {
return getLockByKey(LOCKER_SUITE_ACCESS_TOKEN);
}
@Override
public Lock getAccessTokenLock(String authCorpId) {
return getLockByKey(String.join(":", authCorpId, LOCKER_ACCESS_TOKEN));
}
@Override
public Lock getAuthCorpJsapiTicketLock(String authCorpId) {
return getLockByKey(String.join(":", authCorpId, LOCKER_CORP_JSAPI_TICKET));
}
@Override
public Lock getSuiteJsapiTicketLock(String authCorpId) {
return getLockByKey(String.join(":", authCorpId, LOCKER_SUITE_JSAPI_TICKET));
}
private Lock getLockByKey(String key) {
// 最终key的模式:(keyPrefix:)wechat_tp_lock:suiteId:(authCorpId):lockKey
// 其中keyPrefix目前不支持外部配置,authCorpId只有涉及到corpAccessToken, suiteJsapiTicket, authCorpJsapiTicket时才会拼上
return this.wxRedisOps.getLock(String.join(":", keyWithPrefix(LOCK_KEY + this.suiteId), key));
}
/**
* 单独处理provider,且不应和suite 有关系
*/
private Lock getProviderLockByKey(String key) {
return this.wxRedisOps.getLock(String.join(":", providerKeyWithPrefix(LOCK_KEY), key));
}
@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}
@Override
public boolean autoRefreshToken() {
return false;
}
@Override
public String toString() {
return WxCpGsonBuilder.create().toJson(this);
}
/**
* 一个provider 会有多个suite,需要唯一标识作为前缀
*/
private String keyWithPrefix(String key) {
return keyPrefix + ":" + suiteId + ":" + key;
}
/**
* provider 应该独享一个key,且不和任何suite关联
* 一个provider 会有多个suite,不同的suite 都应该指向同一个provider 的数据
*/
private String providerKeyWithPrefix(String key) {
return keyPrefix + ":" + corpId + ":" + key;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpDefaultConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpDefaultConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.File;
import java.io.Serializable;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化.
*
* @author Daniel Qian
*/
public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
private static final long serialVersionUID = 1154541446729462780L;
/**
* The Access token.
*/
protected volatile String accessToken;
/**
* The Access token lock.
*/
protected transient Lock accessTokenLock = new ReentrantLock();
/**
* The Agent id.
*/
protected volatile Integer agentId;
/**
* The Jsapi ticket lock.
*/
protected transient Lock jsapiTicketLock = new ReentrantLock();
/**
* The Agent jsapi ticket lock.
*/
protected transient Lock agentJsapiTicketLock = new ReentrantLock();
private volatile String corpId;
private volatile String corpSecret;
private volatile String token;
private volatile String aesKey;
private volatile long expiresTime;
/**
* 会话存档私钥以及sdk路径
*/
private volatile String msgAuditSecret;
private volatile String msgAuditPriKey;
private volatile String msgAuditLibPath;
/**
* 会话存档SDK及其过期时间
*/
private volatile long msgAuditSdk;
private volatile long msgAuditSdkExpiresTime;
private volatile String oauth2redirectUri;
private volatile String httpProxyHost;
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
private volatile String jsapiTicket;
private volatile long jsapiTicketExpiresTime;
private volatile String agentJsapiTicket;
private volatile long agentJsapiTicketExpiresTime;
private volatile File tmpDirFile;
private transient volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private volatile String baseApiUrl;
private volatile String webhookKey;
@Override
public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl;
}
@Override
public String getApiUrl(String path) {
if (baseApiUrl == null) {
baseApiUrl = WxCpApiPathConsts.DEFAULT_CP_BASE_URL;
}
return baseApiUrl + path;
}
@Override
public String getAccessToken() {
return this.accessToken;
}
/**
* Sets access token.
*
* @param accessToken the access token
*/
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
@Override
public Lock getAccessTokenLock() {
return this.accessTokenLock;
}
@Override
public boolean isAccessTokenExpired() {
return System.currentTimeMillis() > this.expiresTime;
}
@Override
public void expireAccessToken() {
this.expiresTime = 0;
}
@Override
public synchronized void updateAccessToken(WxAccessToken accessToken) {
updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
}
@Override
public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) {
this.accessToken = accessToken;
this.expiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
}
@Override
public String getJsapiTicket() {
return this.jsapiTicket;
}
/**
* Sets jsapi ticket.
*
* @param jsapiTicket the jsapi ticket
*/
public void setJsapiTicket(String jsapiTicket) {
this.jsapiTicket = jsapiTicket;
}
@Override
public Lock getJsapiTicketLock() {
return this.jsapiTicketLock;
}
/**
* Gets jsapi ticket expires time.
*
* @return the jsapi ticket expires time
*/
public long getJsapiTicketExpiresTime() {
return this.jsapiTicketExpiresTime;
}
/**
* Sets jsapi ticket expires time.
*
* @param jsapiTicketExpiresTime the jsapi ticket expires time
*/
public void setJsapiTicketExpiresTime(long jsapiTicketExpiresTime) {
this.jsapiTicketExpiresTime = jsapiTicketExpiresTime;
}
@Override
public boolean isJsapiTicketExpired() {
return System.currentTimeMillis() > this.jsapiTicketExpiresTime;
}
@Override
public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) {
this.jsapiTicket = jsapiTicket;
// 预留200秒的时间
this.jsapiTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
}
@Override
public String getAgentJsapiTicket() {
return this.agentJsapiTicket;
}
@Override
public Lock getAgentJsapiTicketLock() {
return this.agentJsapiTicketLock;
}
@Override
public boolean isAgentJsapiTicketExpired() {
return System.currentTimeMillis() > this.agentJsapiTicketExpiresTime;
}
@Override
public void expireAgentJsapiTicket() {
this.agentJsapiTicketExpiresTime = 0;
}
@Override
public void updateAgentJsapiTicket(String jsapiTicket, int expiresInSeconds) {
this.agentJsapiTicket = jsapiTicket;
// 预留200秒的时间
this.agentJsapiTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
}
@Override
public void expireJsapiTicket() {
this.jsapiTicketExpiresTime = 0;
}
@Override
public String getCorpId() {
return this.corpId;
}
/**
* Sets corp id.
*
* @param corpId the corp id
*/
public void setCorpId(String corpId) {
this.corpId = corpId;
}
@Override
public String getCorpSecret() {
return this.corpSecret;
}
/**
* Sets corp secret.
*
* @param corpSecret the corp secret
*/
public void setCorpSecret(String corpSecret) {
this.corpSecret = corpSecret;
}
@Override
public String getToken() {
return this.token;
}
/**
* Sets token.
*
* @param token the token
*/
public void setToken(String token) {
this.token = token;
}
@Override
public long getExpiresTime() {
return this.expiresTime;
}
/**
* Sets expires time.
*
* @param expiresTime the expires time
*/
public void setExpiresTime(long expiresTime) {
this.expiresTime = expiresTime;
}
@Override
public String getAesKey() {
return this.aesKey;
}
@Override
public String getMsgAuditPriKey() {
return this.msgAuditPriKey;
}
@Override
public String getMsgAuditLibPath() {
return this.msgAuditLibPath;
}
/**
* Sets aes key.
*
* @param aesKey the aes key
*/
public void setAesKey(String aesKey) {
this.aesKey = aesKey;
}
@Override
public Integer getAgentId() {
return this.agentId;
}
/**
* Sets agent id.
*
* @param agentId the agent id
*/
public void setAgentId(Integer agentId) {
this.agentId = agentId;
}
/**
* 设置企微会话存档路径.
*
* @param msgAuditLibPath 会话存档具体路径
*/
public void setMsgAuditLibPath(String msgAuditLibPath) {
this.msgAuditLibPath = msgAuditLibPath;
}
/**
* 设置会话存档私钥
*
* @param msgAuditPriKey 会话存档私钥
*/
public void setMsgAuditPriKey(String msgAuditPriKey) {
this.msgAuditPriKey = msgAuditPriKey;
}
@Override
public String getOauth2redirectUri() {
return this.oauth2redirectUri;
}
/**
* Sets oauth 2 redirect uri.
*
* @param oauth2redirectUri the oauth 2 redirect uri
*/
public void setOauth2redirectUri(String oauth2redirectUri) {
this.oauth2redirectUri = oauth2redirectUri;
}
@Override
public String getHttpProxyHost() {
return this.httpProxyHost;
}
/**
* Sets http proxy host.
*
* @param httpProxyHost the http proxy host
*/
public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost;
}
@Override
public int getHttpProxyPort() {
return this.httpProxyPort;
}
/**
* Sets http proxy port.
*
* @param httpProxyPort the http proxy port
*/
public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort;
}
@Override
public String getHttpProxyUsername() {
return this.httpProxyUsername;
}
/**
* Sets http proxy username.
*
* @param httpProxyUsername the http proxy username
*/
public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername;
}
@Override
public String getHttpProxyPassword() {
return this.httpProxyPassword;
}
/**
* Sets http proxy password.
*
* @param httpProxyPassword the http proxy password
*/
public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword;
}
@Override
public String toString() {
return WxCpGsonBuilder.create().toJson(this);
}
@Override
public File getTmpDirFile() {
return this.tmpDirFile;
}
/**
* Sets tmp dir file.
*
* @param tmpDirFile the tmp dir file
*/
public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile;
}
@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}
/**
* Sets apache http client builder.
*
* @param apacheHttpClientBuilder the apache http client builder
*/
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
@Override
public boolean autoRefreshToken() {
return true;
}
@Override
public String getWebhookKey() {
return this.webhookKey;
}
/**
* Sets webhook key.
*
* @param webhookKey the webhook key
* @return the webhook key
*/
public WxCpDefaultConfigImpl setWebhookKey(String webhookKey) {
this.webhookKey = webhookKey;
return this;
}
@Override
public String getMsgAuditSecret() {
return this.msgAuditSecret;
}
/**
* 设置会话存档secret
*
* @param msgAuditSecret the msg audit secret
* @return this
*/
public WxCpDefaultConfigImpl setMsgAuditSecret(String msgAuditSecret) {
this.msgAuditSecret = msgAuditSecret;
return this;
}
@Override
public long getMsgAuditSdk() {
return this.msgAuditSdk;
}
@Override
public boolean isMsgAuditSdkExpired() {
return System.currentTimeMillis() > this.msgAuditSdkExpiresTime;
}
@Override
public synchronized void updateMsgAuditSdk(long sdk, int expiresInSeconds) {
this.msgAuditSdk = sdk;
// 预留200秒的时间
this.msgAuditSdkExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
}
@Override
public void expireMsgAuditSdk() {
this.msgAuditSdkExpiresTime = 0;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpDefaultConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpDefaultConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
* 基于内存的微信配置provider,在实际生产环境中应该将这些配置持久化.
*
* @author someone
*/
public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializable {
private static final long serialVersionUID = 6678780920621872824L;
private final transient Map<String, Lock> providerAccessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> suiteAccessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> accessTokenLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> authCorpJsapiTicketLocker = new ConcurrentHashMap<>();
private final transient Map<String, Lock> authSuiteJsapiTicketLocker = new ConcurrentHashMap<>();
/**
* 企微服务商企业ID & 企业secret,来自于企微配置
*/
protected volatile String corpId;
/**
* 服务商secret
*/
protected volatile String providerSecret;
private volatile String providerToken;
private volatile long providerTokenExpiresTime;
/**
* 第三方应用的其他配置,来自于企微配置
*/
protected volatile String suiteId;
protected volatile String suiteSecret;
/**
* 第三方应用的token,用来检查应用的签名
*/
protected volatile String token;
private volatile String suiteAccessToken;
private volatile long suiteAccessTokenExpiresTime;
/**
* 第三方应用的EncodingAESKey,用来检查签名
*/
protected volatile String encodingAESKey;
private volatile String suiteTicket;
private volatile long suiteTicketExpiresTime;
private volatile String oauth2redirectUri;
private final Map<String, String> authCorpAccessTokenMap = new HashMap<>();
private final Map<String, Long> authCorpAccessTokenExpireTimeMap = new HashMap<>();
private final Map<String, String> authCorpJsApiTicketMap = new HashMap<>();
private final Map<String, Long> authCorpJsApiTicketExpireTimeMap = new HashMap<>();
private final Map<String, String> authSuiteJsApiTicketMap = new HashMap<>();
private final Map<String, Long> authSuiteJsApiTicketExpireTimeMap = new HashMap<>();
private volatile String httpProxyHost;
private volatile int httpProxyPort;
private volatile String httpProxyUsername;
private volatile String httpProxyPassword;
private volatile File tmpDirFile;
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private volatile String baseApiUrl;
@Override
public void setBaseApiUrl(String baseUrl) {
this.baseApiUrl = baseUrl;
}
@Override
public String getApiUrl(String path) {
if (baseApiUrl == null) {
baseApiUrl = "https://qyapi.weixin.qq.com";
}
return baseApiUrl + path;
}
@Override
public String getSuiteAccessToken() {
return this.suiteAccessToken;
}
/**
* Sets suite access token.
*
* @param suiteAccessToken the suite access token
*/
public void setSuiteAccessToken(String suiteAccessToken) {
this.suiteAccessToken = suiteAccessToken;
}
@Override
public WxAccessToken getSuiteAccessTokenEntity() {
WxAccessToken accessToken = new WxAccessToken();
int expiresIn = Math.toIntExact((this.suiteAccessTokenExpiresTime - System.currentTimeMillis()) / 1000L);
accessToken.setExpiresIn(expiresIn <= 0 ? -1 : expiresIn);
accessToken.setAccessToken(this.suiteAccessToken);
return accessToken;
}
@Override
public boolean isSuiteAccessTokenExpired() {
return System.currentTimeMillis() > this.suiteAccessTokenExpiresTime;
}
@Override
public void expireSuiteAccessToken() {
this.suiteAccessTokenExpiresTime = 0;
}
@Override
public synchronized void updateSuiteAccessToken(WxAccessToken suiteAccessToken) {
updateSuiteAccessToken(suiteAccessToken.getAccessToken(), suiteAccessToken.getExpiresIn());
}
@Override
public synchronized void updateSuiteAccessToken(String suiteAccessToken, int expiresInSeconds) {
this.suiteAccessToken = suiteAccessToken;
this.suiteAccessTokenExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
}
/**
* Sets suite access token expires time.
*
* @param suiteAccessTokenExpiresTime the suite access token expires time
*/
@Deprecated
public void setSuiteAccessTokenExpiresTime(long suiteAccessTokenExpiresTime) {
this.suiteAccessTokenExpiresTime = suiteAccessTokenExpiresTime;
}
@Override
public String getSuiteTicket() {
return this.suiteTicket;
}
/**
* Sets suite ticket.
*
* @param suiteTicket the suite ticket
*/
@Deprecated
public void setSuiteTicket(String suiteTicket) {
this.suiteTicket = suiteTicket;
}
@Override
public boolean isSuiteTicketExpired() {
return System.currentTimeMillis() > this.suiteTicketExpiresTime;
}
@Override
public void expireSuiteTicket() {
this.suiteTicketExpiresTime = 0;
}
@Override
public synchronized void updateSuiteTicket(String suiteTicket, int expiresInSeconds) {
this.suiteTicket = suiteTicket;
// 预留200秒的时间
this.suiteTicketExpiresTime = System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L;
}
/**
* Gets suite ticket expires time.
*
* @return the suite ticket expires time
*/
@Deprecated
public long getSuiteTicketExpiresTime() {
return this.suiteTicketExpiresTime;
}
/**
* Sets suite ticket expires time.
*
* @param suiteTicketExpiresTime the suite ticket expires time
*/
@Deprecated
public void setSuiteTicketExpiresTime(long suiteTicketExpiresTime) {
this.suiteTicketExpiresTime = suiteTicketExpiresTime;
}
@Override
public String getSuiteId() {
return this.suiteId;
}
/**
* Sets suite id.
*
* @param suiteId
*/
public void setSuiteId(String suiteId) {
this.suiteId = suiteId;
}
@Override
public String getSuiteSecret() {
return this.suiteSecret;
}
/**
* Sets suite secret.
*/
public void setSuiteSecret(String corpSecret) {
this.suiteSecret = corpSecret;
}
@Override
public String getToken() {
return this.token;
}
/**
* Sets token.
*
* @param token the token
*/
public void setToken(String token) {
this.token = token;
}
@Override
public String getEncodingAESKey() {
return this.encodingAESKey;
}
/**
* Sets aes key. encodingAESKey
*
* @param encodingAESKey the aes key
*/
public void setEncodingAESKey(String encodingAESKey) {
this.encodingAESKey = encodingAESKey;
}
@Override
public String getCorpId() {
return this.corpId;
}
/**
* Sets corp id.
*
* @param corpId the corp id
*/
public void setCorpId(String corpId) {
this.corpId = corpId;
}
@Override
public String getCorpSecret() {
return this.providerSecret;
}
@Override
public void setProviderSecret(String providerSecret) {
this.providerSecret = providerSecret;
}
@Override
public String getProviderSecret() {
return providerSecret;
}
@Override
public String getAccessToken(String authCorpId) {
return authCorpAccessTokenMap.get(authCorpId);
}
@Override
public WxAccessToken getAccessTokenEntity(String authCorpId) {
String accessToken = authCorpAccessTokenMap.getOrDefault(authCorpId, StringUtils.EMPTY);
Long expire = authCorpAccessTokenExpireTimeMap.getOrDefault(authCorpId, 0L);
WxAccessToken accessTokenEntity = new WxAccessToken();
accessTokenEntity.setAccessToken(accessToken);
accessTokenEntity.setExpiresIn((int) ((expire - System.currentTimeMillis()) / 1000 + 200));
return accessTokenEntity;
}
@Override
public boolean isAccessTokenExpired(String authCorpId) {
//不存在或者过期
return authCorpAccessTokenExpireTimeMap.get(authCorpId) == null
|| System.currentTimeMillis() > authCorpAccessTokenExpireTimeMap.get(authCorpId);
}
@Override
public void expireAccessToken(String authCorpId) {
authCorpAccessTokenMap.remove(authCorpId);
authCorpAccessTokenExpireTimeMap.remove(authCorpId);
}
@Override
public void updateAccessToken(String authCorpId, String accessToken, int expiredInSeconds) {
authCorpAccessTokenMap.put(authCorpId, accessToken);
// 预留200秒的时间
authCorpAccessTokenExpireTimeMap.put(authCorpId, System.currentTimeMillis() + (expiredInSeconds - 200) * 1000L);
}
@Override
public String getAuthCorpJsApiTicket(String authCorpId) {
return this.authCorpJsApiTicketMap.get(authCorpId);
}
@Override
public boolean isAuthCorpJsApiTicketExpired(String authCorpId) {
Long t = this.authCorpJsApiTicketExpireTimeMap.get(authCorpId);
if (t == null) {
return true;
}
return System.currentTimeMillis() > t;
}
@Override
public void expireAuthCorpJsApiTicket(String authCorpId) {
this.authCorpJsApiTicketMap.remove(authCorpId);
this.authCorpJsApiTicketExpireTimeMap.remove(authCorpId);
}
@Override
public void updateAuthCorpJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds) {
// 应该根据不同的授权企业做区分
authCorpJsApiTicketMap.put(authCorpId, jsApiTicket);
// 预留200秒的时间
authCorpJsApiTicketExpireTimeMap.put(authCorpId, System.currentTimeMillis() + (expiredInSeconds - 200) * 1000L);
}
@Override
public String getAuthSuiteJsApiTicket(String authCorpId) {
return authSuiteJsApiTicketMap.get(authCorpId);
}
@Override
public boolean isAuthSuiteJsApiTicketExpired(String authCorpId) {
Long t = authSuiteJsApiTicketExpireTimeMap.get(authCorpId);
if (t == null) {
return true;
}
return System.currentTimeMillis() > t;
}
@Override
public void expireAuthSuiteJsApiTicket(String authCorpId) {
this.authSuiteJsApiTicketMap.remove(authCorpId);
this.authSuiteJsApiTicketExpireTimeMap.remove(authCorpId);
}
@Override
public void updateAuthSuiteJsApiTicket(String authCorpId, String jsApiTicket, int expiredInSeconds) {
// 应该根据不同的授权企业做区分
authSuiteJsApiTicketMap.put(authCorpId, jsApiTicket);
// 预留200秒的时间
authSuiteJsApiTicketExpireTimeMap.put(authCorpId, System.currentTimeMillis() + (expiredInSeconds - 200) * 1000L);
}
@Override
public boolean isProviderTokenExpired() {
return System.currentTimeMillis() > providerTokenExpiresTime;
}
@Override
public void updateProviderToken(String providerToken, int expiredInSeconds) {
this.providerToken = providerToken;
this.providerTokenExpiresTime = System.currentTimeMillis() + expiredInSeconds * 1000L;
}
@Override
public String getProviderToken() {
return providerToken;
}
@Override
public WxCpProviderToken getProviderTokenEntity() {
return null;
}
@Override
public void expireProviderToken() {
this.providerTokenExpiresTime = 0L;
}
/**
* Sets oauth 2 redirect uri.
*
* @param oauth2redirectUri the oauth 2 redirect uri
*/
public void setOauth2redirectUri(String oauth2redirectUri) {
this.oauth2redirectUri = oauth2redirectUri;
}
@Override
public String getHttpProxyHost() {
return this.httpProxyHost;
}
/**
* Sets http proxy host.
*
* @param httpProxyHost the http proxy host
*/
public void setHttpProxyHost(String httpProxyHost) {
this.httpProxyHost = httpProxyHost;
}
@Override
public int getHttpProxyPort() {
return this.httpProxyPort;
}
/**
* Sets http proxy port.
*
* @param httpProxyPort the http proxy port
*/
public void setHttpProxyPort(int httpProxyPort) {
this.httpProxyPort = httpProxyPort;
}
@Override
public String getHttpProxyUsername() {
return this.httpProxyUsername;
}
/**
* Sets http proxy username.
*
* @param httpProxyUsername the http proxy username
*/
public void setHttpProxyUsername(String httpProxyUsername) {
this.httpProxyUsername = httpProxyUsername;
}
@Override
public String getHttpProxyPassword() {
return this.httpProxyPassword;
}
/**
* Sets http proxy password.
*
* @param httpProxyPassword the http proxy password
*/
public void setHttpProxyPassword(String httpProxyPassword) {
this.httpProxyPassword = httpProxyPassword;
}
@Override
public String toString() {
return WxCpGsonBuilder.create().toJson(this);
}
@Override
public File getTmpDirFile() {
return this.tmpDirFile;
}
/**
* Sets tmp dir file.
*
* @param tmpDirFile the tmp dir file
*/
public void setTmpDirFile(File tmpDirFile) {
this.tmpDirFile = tmpDirFile;
}
@Override
public Lock getProviderAccessTokenLock() {
return this.providerAccessTokenLocker
.computeIfAbsent(String.join(":", this.suiteId, this.corpId), key -> new ReentrantLock());
}
@Override
public Lock getSuiteAccessTokenLock() {
return this.suiteAccessTokenLocker.computeIfAbsent(this.suiteId, key -> new ReentrantLock());
}
@Override
public Lock getAccessTokenLock(String authCorpId) {
return this.accessTokenLocker
.computeIfAbsent(String.join(":", this.suiteId, authCorpId), key -> new ReentrantLock());
}
@Override
public Lock getAuthCorpJsapiTicketLock(String authCorpId) {
return this.authCorpJsapiTicketLocker
.computeIfAbsent(String.join(":", this.suiteId, authCorpId), key -> new ReentrantLock());
}
@Override
public Lock getSuiteJsapiTicketLock(String authCorpId) {
return this.authSuiteJsapiTicketLocker
.computeIfAbsent(String.join(":", this.suiteId, authCorpId), key -> new ReentrantLock());
}
@Override
public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}
/**
* Sets apache http client builder.
*
* @param apacheHttpClientBuilder the apache http client builder
*/
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
@Override
public boolean autoRefreshToken() {
return true;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpRedissonConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpRedissonConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.Builder;
import lombok.Data;
import lombok.NonNull;
import me.chanjar.weixin.common.redis.RedissonWxRedisOps;
import org.redisson.api.RedissonClient;
/**
* 基于Redisson的实现
*
* @author yuanqixun created on 2020 /5/13
* @author yl
*/
public class WxCpTpRedissonConfigImpl extends AbstractWxCpTpInRedisConfigImpl {
private static final long serialVersionUID = -5674792341070783967L;
public WxCpTpRedissonConfigImpl(@NonNull RedissonClient redissonClient) {
this(redissonClient, null);
}
public WxCpTpRedissonConfigImpl(@NonNull RedissonClient redissonClient, String keyPrefix) {
super(new RedissonWxRedisOps(redissonClient), keyPrefix);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpRedisTemplateConfigImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpRedisTemplateConfigImpl.java | package me.chanjar.weixin.cp.config.impl;
import lombok.Builder;
import lombok.NonNull;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import org.springframework.data.redis.core.StringRedisTemplate;
/**
* 基于 RedisTemplate 的实现
*
* @author yl
* created on 2023/04/23
*/
public class WxCpTpRedisTemplateConfigImpl extends AbstractWxCpTpInRedisConfigImpl {
private static final long serialVersionUID = -1660004125413310620L;
public WxCpTpRedisTemplateConfigImpl(@NonNull StringRedisTemplate stringRedisTemplate) {
this(stringRedisTemplate, null);
}
public WxCpTpRedisTemplateConfigImpl(@NonNull StringRedisTemplate stringRedisTemplate, String keyPrefix) {
super(new RedisTemplateWxRedisOps(stringRedisTemplate), keyPrefix);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/WxCpCgService.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/WxCpCgService.java | package me.chanjar.weixin.cp.corpgroup.service;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.corpgroup.WxCpCorpGroupCorpGetTokenReq;
import me.chanjar.weixin.cp.bean.corpgroup.WxCpMaTransferSession;
import me.chanjar.weixin.cp.config.WxCpCorpGroupConfigStorage;
/**
* 企业微信企业互联API的Service.
*
* @author libo
*/
public interface WxCpCgService {
/**
* Update corp access token.
*
* @param corpId .
* @param agentId .
* @param corpAccessToken the corp access token
* @param expiresInSeconds the expires in seconds
*/
void updateCorpAccessToken(String corpId, Integer agentId, String corpAccessToken, int expiresInSeconds);
String getCorpAccessToken(String corpId, Integer agentId, Integer businessType) throws WxErrorException;
String getCorpAccessToken(String corpId, Integer agentId, Integer businessType, boolean forceRefresh) throws WxErrorException;
/**
* 授权企业的access token相关
*
* @param corpId the corp id
* @param agentId
* @param businessType
* @return the access token
*/
WxAccessToken getCorpAccessTokenEntity(String corpId, Integer agentId, Integer businessType) throws WxErrorException;
/**
* Gets access token entity.
*
* @param corpId the corp id
* @param agentId
* @param businessType
* @return the access token entity
*/
WxAccessToken getCorpAccessTokenEntity(String corpId, Integer agentId, Integer businessType, boolean forceRefresh) throws WxErrorException;
/**
* Is access token expired boolean.
*
* @param corpId the corp id
* @param agentId
* @return the boolean
*/
boolean isCorpAccessTokenExpired(String corpId, Integer agentId);
/**
* Expire access token.
*
* @param corpId the corp id
* @param agentId
*/
void expireCorpAccessToken(String corpId, Integer agentId);
/**
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求.
*
* @param url 接口地址
* @param queryParam 请求参数
* @return the string
* @throws WxErrorException the wx error exception
*/
String get(String url, String queryParam, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
/**
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求.
*
* @param url 接口地址
* @param queryParam 请求参数
* @param withoutCorpAccessToken 请求是否忽略CorpAccessToken 默认不忽略-false
* @return the string
* @throws WxErrorException the wx error exception
*/
String get(String url, String queryParam, boolean withoutCorpAccessToken, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
/**
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的POST请求.
*
* @param url 接口地址
* @param postData 请求body字符串
* @return the string
* @throws WxErrorException the wx error exception
*/
String post(String url, String postData, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
/**
* <pre>
* Service没有实现某个API的时候,可以用这个,
* 比{@link #get}和{@link #post}方法更灵活,可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
* 可以参考,{@link MediaUploadRequestExecutor}的实现方法
* </pre>
*
* @param <T> 请求值类型
* @param <E> 返回值类型
* @param executor 执行器
* @param uri 请求地址
* @param data 参数
* @return the t
* @throws WxErrorException the wx error exception
*/
<T, E> T execute(RequestExecutor<T, E> executor, String uri, E data, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
/**
* <pre>
* 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试.
* 默认:1000ms
* </pre>
*
* @param retrySleepMillis 重试休息时间
*/
void setRetrySleepMillis(int retrySleepMillis);
/**
* <pre>
* 设置当微信系统响应系统繁忙时,最大重试次数.
* 默认:5次
* </pre>
*
* @param maxRetryTimes 最大重试次数
*/
void setMaxRetryTimes(int maxRetryTimes);
/**
* 初始化http请求对象
*/
void initHttp();
void setWxCpCorpGroupConfigStorage(WxCpCorpGroupConfigStorage wxCpCorpGroupConfigStorage);
WxCpCorpGroupConfigStorage getWxCpCorpGroupConfigStorage();
/**
* http请求对象.
*
* @return the request http
*/
RequestHttp<?, ?> getRequestHttp();
void setWxCpService(WxCpService wxCpService);
/**
* 互联企业的服务类对象
*
* @return
*/
WxCpLinkedCorpService getLinkedCorpService();
/**
* 获取下级/下游企业小程序session
* https://developer.work.weixin.qq.com/document/path/93355
*
* @param userId
* @param sessionKey
* @return
* @throws WxErrorException
*/
WxCpMaTransferSession getCorpTransferSession(String userId, String sessionKey, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/WxCpLinkedCorpService.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/WxCpLinkedCorpService.java | package me.chanjar.weixin.cp.corpgroup.service;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.corpgroup.WxCpCorpGroupCorpGetTokenReq;
import me.chanjar.weixin.cp.bean.linkedcorp.WxCpLinkedCorpAgentPerm;
import me.chanjar.weixin.cp.bean.linkedcorp.WxCpLinkedCorpDepartment;
import me.chanjar.weixin.cp.bean.linkedcorp.WxCpLinkedCorpUser;
import java.util.List;
/**
* 互联企业相关接口
*
* @author libo Email: 422423229@qq.com
* @since 27/2/2023 9:57 PM
*/
public interface WxCpLinkedCorpService {
WxCpLinkedCorpAgentPerm getLinkedCorpAgentPerm(WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
WxCpLinkedCorpUser getLinkedCorpUser(String userId, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
List<WxCpLinkedCorpUser> getLinkedCorpSimpleUserList(String departmentId, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
List<WxCpLinkedCorpUser> getLinkedCorpUserList(String departmentId, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
List<WxCpLinkedCorpDepartment> getLinkedCorpDepartmentList(String departmentId, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/WxCpCgServiceHttpComponentsImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/WxCpCgServiceHttpComponentsImpl.java | package me.chanjar.weixin.cp.corpgroup.service.impl;
import me.chanjar.weixin.common.util.http.HttpClientType;
import me.chanjar.weixin.common.util.http.hc.DefaultHttpComponentsClientBuilder;
import me.chanjar.weixin.common.util.http.hc.HttpComponentsClientBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.HttpHost;
/**
* @author altusea
*/
public class WxCpCgServiceHttpComponentsImpl extends BaseWxCpCgServiceImpl<CloseableHttpClient, HttpHost> {
private CloseableHttpClient httpClient;
private HttpHost httpProxy;
@Override
public CloseableHttpClient getRequestHttpClient() {
return httpClient;
}
@Override
public HttpHost getRequestHttpProxy() {
return httpProxy;
}
@Override
public HttpClientType getRequestType() {
return HttpClientType.HTTP_COMPONENTS;
}
@Override
public void initHttp() {
HttpComponentsClientBuilder apacheHttpClientBuilder = DefaultHttpComponentsClientBuilder.get();
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
.httpProxyPort(this.configStorage.getHttpProxyPort())
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
.httpProxyPassword(this.configStorage.getHttpProxyPassword().toCharArray());
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());
}
this.httpClient = apacheHttpClientBuilder.build();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/BaseWxCpCgServiceImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/BaseWxCpCgServiceImpl.java | package me.chanjar.weixin.cp.corpgroup.service.impl;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxCpErrorMsgEnum;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.util.DataUtils;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.corpgroup.WxCpCorpGroupCorpGetTokenReq;
import me.chanjar.weixin.cp.bean.corpgroup.WxCpMaTransferSession;
import me.chanjar.weixin.cp.config.WxCpCorpGroupConfigStorage;
import me.chanjar.weixin.cp.corpgroup.service.WxCpCgService;
import me.chanjar.weixin.cp.corpgroup.service.WxCpLinkedCorpService;
import java.io.IOException;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.CorpGroup.*;
/**
* @author libo Email: 422423229@qq.com
* @since 1/3/2023 5:45 PM
*/
@Slf4j
public abstract class BaseWxCpCgServiceImpl<H, P> implements WxCpCgService, RequestHttp<H, P> {
WxCpService wxCpService;
/**
* The Config storage.
*/
protected WxCpCorpGroupConfigStorage configStorage;
private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
private final WxCpLinkedCorpService linkedCorpService = new WxCpLinkedCorpServiceImpl(this);
@Override
public void updateCorpAccessToken(String corpId, Integer agentId, String corpAccessToken, int expiresInSeconds) {
}
@Override
public String getCorpAccessToken(String corpId, Integer agentId, Integer businessType) throws WxErrorException {
return getCorpAccessToken(corpId, agentId, businessType, false);
}
@Override
public String getCorpAccessToken(String corpId, Integer agentId, Integer businessType, boolean forceRefresh) throws WxErrorException {
if (!this.configStorage.isCorpAccessTokenExpired(corpId, agentId) && !forceRefresh) {
return this.configStorage.getCorpAccessToken(corpId, agentId);
}
synchronized (this) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("corpid", corpId);
jsonObject.addProperty("agentid", agentId);
jsonObject.addProperty("business_type", businessType);
final String url = this.wxCpService.getWxCpConfigStorage().getApiUrl(CORP_GET_TOKEN);
String responseContent = this.wxCpService.post(url, jsonObject);
WxAccessToken corpToken = WxAccessToken.fromJson(responseContent);
this.configStorage.updateCorpAccessToken(corpId, agentId, corpToken.getAccessToken(), corpToken.getExpiresIn());
}
return this.configStorage.getCorpAccessToken(corpId, agentId);
}
@Override
public WxAccessToken getCorpAccessTokenEntity(String corpId, Integer agentId, Integer businessType) throws WxErrorException {
return this.getCorpAccessTokenEntity(corpId, agentId, businessType, false);
}
@Override
public WxAccessToken getCorpAccessTokenEntity(String corpId, Integer agentId, Integer businessType, boolean forceRefresh) throws WxErrorException {
return this.configStorage.getCorpAccessTokenEntity(corpId, agentId);
}
@Override
public boolean isCorpAccessTokenExpired(String corpId, Integer agentId) {
return this.configStorage.isCorpAccessTokenExpired(corpId, agentId);
}
@Override
public void expireCorpAccessToken(String corpId, Integer agentId) {
this.configStorage.expireCorpAccessToken(corpId, agentId);
}
@Override
public String get(String url, String queryParam, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
return execute(SimpleGetRequestExecutor.create(this), url, queryParam, req);
}
@Override
public String get(String url, String queryParam, boolean withoutCorpAccessToken, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
return execute(SimpleGetRequestExecutor.create(this), url, queryParam, withoutCorpAccessToken, req);
}
@Override
public String post(String url, String postData, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
return execute(SimplePostRequestExecutor.create(this), url, postData, false, req);
}
/**
* Post string.
*
* @param url the url
* @param postData the post data
* @param withoutCorpAccessToken the without Corp access token
* @return the string
* @throws WxErrorException the wx error exception
*/
public String post(String url, String postData, boolean withoutCorpAccessToken, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
return execute(SimplePostRequestExecutor.create(this), url, postData, withoutCorpAccessToken, req);
}
/**
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求.
*/
@Override
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
return execute(executor, uri, data, false, req);
}
/**
* Execute t.
*
* @param <T> the type parameter
* @param <E> the type parameter
* @param executor the executor
* @param uri the uri
* @param data the data
* @param withoutCorpAccessToken the without Corp access token
* @return the t
* @throws WxErrorException the wx error exception
*/
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data, boolean withoutCorpAccessToken, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
int retryTimes = 0;
do {
try {
return this.executeInternal(executor, uri, data, withoutCorpAccessToken, req);
} catch (WxErrorException e) {
if (retryTimes + 1 > this.maxRetryTimes) {
log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
//最后一次重试失败后,直接抛出异常,不再等待
throw new WxRuntimeException("微信服务端异常,超出重试次数");
}
WxError error = e.getError();
/*
* -1 系统繁忙, 1000ms后重试
*/
if (error.getErrorCode() == -1) {
int sleepMillis = this.retrySleepMillis * (1 << retryTimes);
try {
log.debug("微信系统繁忙,{} ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
Thread.sleep(sleepMillis);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
} else {
throw e;
}
}
} while (retryTimes++ < this.maxRetryTimes);
log.warn("重试达到最大次数【{}】", this.maxRetryTimes);
throw new WxRuntimeException("微信服务端异常,超出重试次数");
}
/**
* Execute internal t.
*
* @param <T> the type parameter
* @param <E> the type parameter
* @param executor the executor
* @param uri the uri
* @param data the data
* @return the t
* @throws WxErrorException the wx error exception
*/
protected <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
return executeInternal(executor, uri, data, false, req);
}
/**
* Execute internal t.
*
* @param <T> the type parameter
* @param <E> the type parameter
* @param executor the executor
* @param uri the uri
* @param data the data
* @param withoutCorpAccessToken the without Corp access token
* @return the t
* @throws WxErrorException the wx error exception
*/
protected <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data,
boolean withoutCorpAccessToken, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
E dataForLog = DataUtils.handleDataWithSecret(data);
if (uri.contains("access_token=")) {
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
}
String uriWithAccessToken;
if (!withoutCorpAccessToken) {
String corpAccessToken = getCorpAccessToken(req.getCorpId(), req.getAgentId(), req.getBusinessType());
uriWithAccessToken = uri + (uri.contains("?") ? "&" : "?") + "access_token=" + corpAccessToken;
} else {
uriWithAccessToken = uri;
}
try {
T result = executor.execute(uriWithAccessToken, data, WxType.CP);
log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
return result;
} catch (WxErrorException e) {
WxError error = e.getError();
/*
* 发生以下情况时尝试刷新Corp_access_token
* 42009 Corp_access_token已过期
*/
if (error.getErrorCode() == WxCpErrorMsgEnum.CODE_42009.getCode()) {
// 强制设置wxCpCorpGroupConfigStorage它的corp access token过期了,这样在下一次请求里就会刷新corp access token
this.configStorage.expireCorpAccessToken(req.getCorpId(), req.getAgentId());
if (this.getWxCpCorpGroupConfigStorage().autoRefreshToken()) {
log.warn("即将重新获取新的access_token,错误代码:{},错误信息:{}", error.getErrorCode(), error.getErrorMsg());
return this.execute(executor, uri, data, req);
}
}
if (error.getErrorCode() != 0) {
log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
throw new WxErrorException(error, e);
}
return null;
} catch (IOException e) {
log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
throw new WxRuntimeException(e);
}
}
@Override
public void setWxCpCorpGroupConfigStorage(WxCpCorpGroupConfigStorage wxCpCorpGroupConfigStorage) {
this.configStorage = wxCpCorpGroupConfigStorage;
this.initHttp();
}
@Override
public WxCpCorpGroupConfigStorage getWxCpCorpGroupConfigStorage() {
return configStorage;
}
@Override
public void setRetrySleepMillis(int retrySleepMillis) {
this.retrySleepMillis = retrySleepMillis;
}
@Override
public void setMaxRetryTimes(int maxRetryTimes) {
this.maxRetryTimes = maxRetryTimes;
}
@Override
public RequestHttp<?, ?> getRequestHttp() {
return this;
}
@Override
public void setWxCpService(WxCpService wxCpService) {
this.wxCpService = wxCpService;
}
@Override
public WxCpLinkedCorpService getLinkedCorpService() {
return linkedCorpService;
}
@Override
public WxCpMaTransferSession getCorpTransferSession(String userId, String sessionKey, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
final String url = this.wxCpService.getWxCpConfigStorage().getApiUrl(MA_TRANSFER_SESSION);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userId);
jsonObject.addProperty("session_key", sessionKey);
String result = this.post(url, jsonObject.toString(), req);
return WxCpMaTransferSession.fromJson(result);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/WxCpLinkedCorpServiceImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/WxCpLinkedCorpServiceImpl.java | package me.chanjar.weixin.cp.corpgroup.service.impl;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.bean.corpgroup.WxCpCorpGroupCorpGetTokenReq;
import me.chanjar.weixin.cp.bean.linkedcorp.WxCpLinkedCorpAgentPerm;
import me.chanjar.weixin.cp.bean.linkedcorp.WxCpLinkedCorpDepartment;
import me.chanjar.weixin.cp.bean.linkedcorp.WxCpLinkedCorpUser;
import me.chanjar.weixin.cp.corpgroup.service.WxCpCgService;
import me.chanjar.weixin.cp.corpgroup.service.WxCpLinkedCorpService;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.util.List;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.LinkedCorp.*;
/**
* 互联企业相关接口实现类
*
* @author libo Email: 422423229@qq.com
* @since 27/2/2023 10:02 PM
*/
@RequiredArgsConstructor
public class WxCpLinkedCorpServiceImpl implements WxCpLinkedCorpService {
private final WxCpCgService cpCgService;
@Override
public WxCpLinkedCorpAgentPerm getLinkedCorpAgentPerm(WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
final String url = this.cpCgService.getWxCpCorpGroupConfigStorage().getApiUrl(GET_PERM_LIST);
JsonObject jsonObject = new JsonObject();
String responseContent = this.cpCgService.post(url, jsonObject.toString(), req);
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpLinkedCorpAgentPerm.class);
}
@Override
public WxCpLinkedCorpUser getLinkedCorpUser(String userId, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
final String url = this.cpCgService.getWxCpCorpGroupConfigStorage().getApiUrl(GET_USER);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userId);
String responseContent = this.cpCgService.post(url, jsonObject.toString(), req);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create().fromJson(tmpJson.get("user_info"),
new TypeToken<WxCpLinkedCorpUser>() {
}.getType()
);
}
@Override
public List<WxCpLinkedCorpUser> getLinkedCorpSimpleUserList(String departmentId, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
final String url = this.cpCgService.getWxCpCorpGroupConfigStorage().getApiUrl(GET_USER_SIMPLELIST);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("department_id", departmentId);
String responseContent = this.cpCgService.post(url, jsonObject.toString(), req);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create().fromJson(tmpJson.get("userlist"),
new TypeToken<List<WxCpLinkedCorpUser>>() {
}.getType()
);
}
@Override
public List<WxCpLinkedCorpUser> getLinkedCorpUserList(String departmentId, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
final String url = this.cpCgService.getWxCpCorpGroupConfigStorage().getApiUrl(GET_USER_LIST);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("department_id", departmentId);
String responseContent = this.cpCgService.post(url, jsonObject.toString(), req);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create().fromJson(tmpJson.get("userlist"),
new TypeToken<List<WxCpLinkedCorpUser>>() {
}.getType()
);
}
@Override
public List<WxCpLinkedCorpDepartment> getLinkedCorpDepartmentList(String departmentId, WxCpCorpGroupCorpGetTokenReq req) throws WxErrorException {
final String url = this.cpCgService.getWxCpCorpGroupConfigStorage().getApiUrl(GET_DEPARTMENT_LIST);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("department_id", departmentId);
String responseContent = this.cpCgService.post(url, jsonObject.toString(), req);
JsonObject tmpJson = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create().fromJson(tmpJson.get("department_list"),
new TypeToken<List<WxCpLinkedCorpDepartment>>() {
}.getType()
);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/WxCpCgServiceApacheHttpClientImpl.java | weixin-java-cp/src/main/java/me/chanjar/weixin/cp/corpgroup/service/impl/WxCpCgServiceApacheHttpClientImpl.java | package me.chanjar.weixin.cp.corpgroup.service.impl;
import me.chanjar.weixin.common.util.http.HttpClientType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
/**
* @author libo Email: 422423229@qq.com
* @since 1/3/2023 6:16 PM
*/
public class WxCpCgServiceApacheHttpClientImpl extends BaseWxCpCgServiceImpl<CloseableHttpClient, HttpHost> {
private CloseableHttpClient httpClient;
private HttpHost httpProxy;
@Override
public CloseableHttpClient getRequestHttpClient() {
return httpClient;
}
@Override
public HttpHost getRequestHttpProxy() {
return httpProxy;
}
@Override
public HttpClientType getRequestType() {
return HttpClientType.APACHE_HTTP;
}
@Override
public void initHttp() {
ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage.getApacheHttpClientBuilder();
if (null == apacheHttpClientBuilder) {
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
}
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
.httpProxyPort(this.configStorage.getHttpProxyPort())
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
.httpProxyPassword(this.configStorage.getHttpProxyPassword());
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());
}
this.httpClient = apacheHttpClientBuilder.build();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/weixin-java-cp/src/main/java/com/tencent/wework/Finance.java | weixin-java-cp/src/main/java/com/tencent/wework/Finance.java | package com.tencent.wework;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
/**
* 企业微信会话内容存档Finance类
* 注意:
* 此类必须配置在com.tencent.wework路径底下,否则会报错:java.lang.UnsatisfiedLinkError: com.xxx.Finance.NewSdk()
* <p>
* Q:JAVA版本的sdk报错UnsatisfiedLinkError?
* A:请检查是否修改了sdk的包名。
* <p>
* <a href="https://developer.work.weixin.qq.com/document/path/91552">官方文档</a>
*
* @author <a href="https://github.com/0katekate0">Wang_Wong</a> created on 2022-01-17
*/
@Slf4j
public class Finance {
private static volatile long sdk = -1L;
private static Finance finance = null;
private static final String SO_FILE = "so";
private static final String DLL_FILE = "dll";
/**
* New sdk long.
*
* @return the long
*/
public static native long NewSdk();
/**
* 初始化函数
* Return值=0表示该API调用成功
*
* @param sdk the sdk
* @param corpid the corpid
* @param secret the secret
* @return 返回是否初始化成功 0 - 成功 !=0 - 失败
*/
public static native int Init(long sdk, String corpid, String secret);
/**
* 拉取聊天记录函数
* Return值=0表示该API调用成功
*
* @param sdk the sdk
* @param seq the seq
* @param limit the limit
* @param proxy the proxy
* @param passwd the passwd
* @param timeout the timeout
* @param chatData the chat data
* @return 返回是否调用成功 0 - 成功 !=0 - 失败
*/
public static native int GetChatData(long sdk, long seq, long limit, String proxy, String passwd, long timeout, long chatData);
/**
* 拉取媒体消息函数
* Return值=0表示该API调用成功
*
* @param sdk the sdk
* @param indexbuf the indexbuf
* @param sdkField the sdk field
* @param proxy the proxy
* @param passwd the passwd
* @param timeout the timeout
* @param mediaData the media data
* @return 返回是否调用成功 0 - 成功 !=0 - 失败
*/
public static native int GetMediaData(long sdk, String indexbuf, String sdkField, String proxy, String passwd, long timeout, long mediaData);
/**
* 解析密文
*
* @param sdk the sdk
* @param encrypt_key the encrypt key
* @param encrypt_msg the encrypt msg
* @param msg the msg
* @return 返回是否调用成功 0 - 成功 !=0 - 失败
*/
public static native int DecryptData(long sdk, String encrypt_key, String encrypt_msg, long msg);
/**
* Destroy sdk.
*
* @param sdk the sdk
*/
public static native void DestroySdk(long sdk);
/**
* New slice long.
*
* @return the long
*/
public static native long NewSlice();
/**
* 释放slice ,和NewSlice成对使用
*
* @param slice the slice
*/
public static native void FreeSlice(long slice);
/**
* 获取slice内容
*
* @param slice the slice
* @return 内容 string
*/
public static native String GetContentFromSlice(long slice);
/**
* 获取slice内容长度
*
* @param slice the slice
* @return 内容 int
*/
public static native int GetSliceLen(long slice);
/**
* New media data long.
*
* @return the long
*/
public static native long NewMediaData();
/**
* Free media data.
*
* @param mediaData the media data
*/
public static native void FreeMediaData(long mediaData);
/**
* 获取 mediadata outindex
*
* @param mediaData the media data
* @return outindex string
*/
public static native String GetOutIndexBuf(long mediaData);
/**
* 获取 mediadata data数据
*
* @param mediaData the media data
* @return data byte [ ]
*/
public static native byte[] GetData(long mediaData);
/**
* Get index len int.
*
* @param mediaData the media data
* @return the int
*/
public static native int GetIndexLen(long mediaData);
/**
* Get data len int.
*
* @param mediaData the media data
* @return the int
*/
public static native int GetDataLen(long mediaData);
/**
* Is media data finish int.
*
* @param mediaData the media data
* @return 1完成 、0未完成
* 判断mediadata是否结束
*/
public static native int IsMediaDataFinish(long mediaData);
/**
* 判断Windows环境
*
* @return boolean boolean
*/
public static boolean isWindows() {
String osName = System.getProperties().getProperty("os.name");
log.info("Loading System Libraries, Current OS Version Is: {}", osName);
return osName.toUpperCase().contains("WINDOWS");
}
/**
* 加载系统类库
*
* @param libFiles 类库配置文件
* @param prefixPath 类库文件的前缀路径
*/
public Finance(List<String> libFiles, String prefixPath) {
boolean isWindows = Finance.isWindows();
for (String file : libFiles) {
String suffix = file.substring(file.lastIndexOf(".") + 1);
if (isWindows) {
// 加载dll文件
if (suffix.equalsIgnoreCase(DLL_FILE)) {
System.load(prefixPath + file);
}
} else {
// 加载so文件
if (suffix.equalsIgnoreCase(SO_FILE)) {
System.load(prefixPath + file);
}
}
}
}
/**
* 初始化类库文件
*
* @param libFiles the lib files
* @param prefixPath the prefix path
* @return finance finance
*/
public static synchronized Finance loadingLibraries(List<String> libFiles, String prefixPath) {
if (finance != null) {
return finance;
}
finance = new Finance(libFiles, prefixPath);
return finance;
}
/**
* 单例sdk
*
* @return long
*/
public static synchronized long SingletonSDK() {
if (sdk > 0) {
return sdk;
}
sdk = Finance.NewSdk();
return sdk;
}
/**
* 销毁sdk,保证线程可见性
*
* @param destroySDK the destroy sdk
*/
public static synchronized void DestroySingletonSDK(long destroySDK) {
sdk = 0L;
Finance.DestroySdk(destroySDK);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-pay-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/pay/properties/WxPayProperties.java | spring-boot-starters/wx-java-pay-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/pay/properties/WxPayProperties.java | package com.binarywang.spring.starter.wxjava.pay.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* <pre>
* 微信支付属性配置类
* Created by Binary Wang on 2019/4/17.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Data
@ConfigurationProperties(prefix = "wx.pay")
public class WxPayProperties {
/**
* 设置微信公众号或者小程序等的appid.
*/
private String appId;
/**
* 微信支付商户号.
*/
private String mchId;
/**
* 微信支付商户密钥.
*/
private String mchKey;
/**
* 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除.
*/
private String subAppId;
/**
* 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除.
*/
private String subMchId;
/**
* apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定.
*/
private String keyPath;
/**
* 微信支付分serviceId
*/
private String serviceId;
/**
* 证书序列号
*/
private String certSerialNo;
/**
* apiV3秘钥
*/
private String apiv3Key;
/**
* 微信支付异步回调地址,通知url必须为直接可访问的url,不能携带参数
*/
private String notifyUrl;
/**
* 微信支付分回调地址
*/
private String payScoreNotifyUrl;
/**
* 微信支付分授权回调地址
*/
private String payScorePermissionNotifyUrl;
/**
* apiv3 商户apiclient_key.pem
*/
private String privateKeyPath;
/**
* apiv3 商户apiclient_cert.pem
*/
private String privateCertPath;
/**
* 公钥ID
*/
private String publicKeyId;
/**
* pub_key.pem证书文件的绝对路径或者以classpath:开头的类路径.
*/
private String publicKeyPath;
/**
* 微信支付是否使用仿真测试环境.
* 默认不使用
*/
private boolean useSandboxEnv;
/**
* 自定义API主机地址,用于替换默认的 https://api.mch.weixin.qq.com
* 例如:http://proxy.company.com:8080
*/
private String apiHostUrl;
/**
* 是否将全部v3接口的请求都添加Wechatpay-Serial请求头,默认不添加
*/
private boolean strictlyNeedWechatPaySerial = false;
/**
* 是否完全使用公钥模式(用以微信从平台证书到公钥的灰度切换),默认不使用
*/
private boolean fullPublicKeyModel = false;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-pay-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/pay/config/WxPayAutoConfiguration.java | spring-boot-starters/wx-java-pay-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/pay/config/WxPayAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.pay.config;
import com.binarywang.spring.starter.wxjava.pay.properties.WxPayProperties;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* <pre>
* 微信支付自动配置
* Created by BinaryWang on 2019/4/17.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Configuration
@EnableConfigurationProperties(WxPayProperties.class)
@ConditionalOnClass(WxPayService.class)
@ConditionalOnProperty(prefix = "wx.pay", value = "enabled", matchIfMissing = true)
public class WxPayAutoConfiguration {
private WxPayProperties properties;
@Autowired
public WxPayAutoConfiguration(WxPayProperties properties) {
this.properties = properties;
}
/**
* 构造微信支付服务对象.
*
* @return 微信支付service
*/
@Bean
@ConditionalOnMissingBean(WxPayService.class)
public WxPayService wxPayService() {
final WxPayServiceImpl wxPayService = new WxPayServiceImpl();
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId()));
payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey()));
payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId()));
payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId()));
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv());
payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl()));
//以下是apiv3以及支付分相关
payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId()));
payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl()));
payConfig.setPayScorePermissionNotifyUrl(StringUtils.trimToNull(this.properties.getPayScorePermissionNotifyUrl()));
payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath()));
payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath()));
payConfig.setCertSerialNo(StringUtils.trimToNull(this.properties.getCertSerialNo()));
payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getApiv3Key()));
payConfig.setPublicKeyId(StringUtils.trimToNull(this.properties.getPublicKeyId()));
payConfig.setPublicKeyPath(StringUtils.trimToNull(this.properties.getPublicKeyPath()));
payConfig.setApiHostUrl(StringUtils.trimToNull(this.properties.getApiHostUrl()));
payConfig.setStrictlyNeedWechatPaySerial(this.properties.isStrictlyNeedWechatPaySerial());
payConfig.setFullPublicKeyModel(this.properties.isFullPublicKeyModel());
wxPayService.setConfig(payConfig);
return wxPayService;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/service/WxMpMultiServices.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/service/WxMpMultiServices.java | package com.binarywang.spring.starter.wxjava.mp.service;
import me.chanjar.weixin.mp.api.WxMpService;
/**
* 企业微信 {@link WxMpService} 所有实例存放类.
*
* @author yl
* created on 2024/1/23
*/
public interface WxMpMultiServices {
/**
* 通过租户 Id 获取 WxMpService
*
* @param tenantId 租户 Id
* @return WxMpService
*/
WxMpService getWxMpService(String tenantId);
/**
* 根据租户 Id,从列表中移除一个 WxMpService 实例
*
* @param tenantId 租户 Id
*/
void removeWxMpService(String tenantId);
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/service/WxMpMultiServicesImpl.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/service/WxMpMultiServicesImpl.java | package com.binarywang.spring.starter.wxjava.mp.service;
import me.chanjar.weixin.mp.api.WxMpService;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 企业微信 {@link WxMpMultiServices} 默认实现
*
* @author yl
* created on 2024/1/23
*/
public class WxMpMultiServicesImpl implements WxMpMultiServices {
private final Map<String, WxMpService> services = new ConcurrentHashMap<>();
@Override
public WxMpService getWxMpService(String tenantId) {
return this.services.get(tenantId);
}
/**
* 根据租户 Id,添加一个 WxMpService 到列表
*
* @param tenantId 租户 Id
* @param wxMpService WxMpService 实例
*/
public void addWxMpService(String tenantId, WxMpService wxMpService) {
this.services.put(tenantId, wxMpService);
}
@Override
public void removeWxMpService(String tenantId) {
this.services.remove(tenantId);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/WxMpMultiServiceConfiguration.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/WxMpMultiServiceConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.configuration;
import com.binarywang.spring.starter.wxjava.mp.configuration.services.WxMpInJedisConfiguration;
import com.binarywang.spring.starter.wxjava.mp.configuration.services.WxMpInMemoryConfiguration;
import com.binarywang.spring.starter.wxjava.mp.configuration.services.WxMpInRedisTemplateConfiguration;
import com.binarywang.spring.starter.wxjava.mp.configuration.services.WxMpInRedissonConfiguration;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpMultiProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* 微信公众号相关服务自动注册
*
* @author yl
* created on 2024/1/23
*/
@Configuration
@EnableConfigurationProperties(WxMpMultiProperties.class)
@Import({
WxMpInJedisConfiguration.class,
WxMpInMemoryConfiguration.class,
WxMpInRedissonConfiguration.class,
WxMpInRedisTemplateConfiguration.class
})
public class WxMpMultiServiceConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/WxMpInRedissonConfiguration.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/WxMpInRedissonConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.configuration.services;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpMultiProperties;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpMultiRedisProperties;
import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServices;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import me.chanjar.weixin.mp.config.impl.WxMpRedissonConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 自动装配基于 redisson 策略配置
*
* @author yl
* created on 2024/1/23
*/
@Configuration
@ConditionalOnProperty(
prefix = WxMpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "redisson"
)
@RequiredArgsConstructor
public class WxMpInRedissonConfiguration extends AbstractWxMpConfiguration {
private final WxMpMultiProperties wxMpMultiProperties;
private final ApplicationContext applicationContext;
@Bean
public WxMpMultiServices wxMpMultiServices() {
return this.wxMpMultiServices(wxMpMultiProperties);
}
@Override
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
return this.configRedisson(wxMpMultiProperties);
}
private WxMpDefaultConfigImpl configRedisson(WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiRedisProperties redisProperties = wxMpMultiProperties.getConfigStorage().getRedis();
RedissonClient redissonClient;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
redissonClient = getRedissonClient(wxMpMultiProperties);
} else {
redissonClient = applicationContext.getBean(RedissonClient.class);
}
return new WxMpRedissonConfigImpl(redissonClient, wxMpMultiProperties.getConfigStorage().getKeyPrefix());
}
private RedissonClient getRedissonClient(WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiProperties.ConfigStorage storage = wxMpMultiProperties.getConfigStorage();
WxMpMultiRedisProperties redis = storage.getRedis();
Config config = new Config();
config.useSingleServer()
.setAddress("redis://" + redis.getHost() + ":" + redis.getPort())
.setDatabase(redis.getDatabase())
.setPassword(redis.getPassword());
config.setTransportMode(TransportMode.NIO);
return Redisson.create(config);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/WxMpInJedisConfiguration.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/WxMpInJedisConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.configuration.services;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpMultiProperties;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpMultiRedisProperties;
import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServices;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* 自动装配基于 jedis 策略配置
*
* @author yl
* created on 2024/1/23
*/
@Configuration
@ConditionalOnProperty(
prefix = WxMpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "jedis"
)
@RequiredArgsConstructor
public class WxMpInJedisConfiguration extends AbstractWxMpConfiguration {
private final WxMpMultiProperties wxMpMultiProperties;
private final ApplicationContext applicationContext;
@Bean
public WxMpMultiServices wxMpMultiServices() {
return this.wxMpMultiServices(wxMpMultiProperties);
}
@Override
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
return this.configRedis(wxMpMultiProperties);
}
private WxMpDefaultConfigImpl configRedis(WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiRedisProperties wxMpMultiRedisProperties = wxMpMultiProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (wxMpMultiRedisProperties != null && StringUtils.isNotEmpty(wxMpMultiRedisProperties.getHost())) {
jedisPool = getJedisPool(wxMpMultiProperties);
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
return new WxMpRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxMpMultiProperties.getConfigStorage().getKeyPrefix());
}
private JedisPool getJedisPool(WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiProperties.ConfigStorage storage = wxMpMultiProperties.getConfigStorage();
WxMpMultiRedisProperties redis = storage.getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
return new JedisPool(config, redis.getHost(), redis.getPort(),
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/WxMpInRedisTemplateConfiguration.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/WxMpInRedisTemplateConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.configuration.services;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpMultiProperties;
import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServices;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
/**
* 自动装配基于 redisTemplate 策略配置
*
* @author yl
* created on 2024/1/23
*/
@Configuration
@ConditionalOnProperty(
prefix = WxMpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "redis_template"
)
@RequiredArgsConstructor
public class WxMpInRedisTemplateConfiguration extends AbstractWxMpConfiguration {
private final WxMpMultiProperties WxMpMultiProperties;
private final ApplicationContext applicationContext;
@Bean
public WxMpMultiServices wxMpMultiServices() {
return this.wxMpMultiServices(WxMpMultiProperties);
}
@Override
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
return this.configRedisTemplate(WxMpMultiProperties);
}
private WxMpDefaultConfigImpl configRedisTemplate(WxMpMultiProperties wxMpMultiProperties) {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
return new WxMpRedisConfigImpl(new RedisTemplateWxRedisOps(redisTemplate),
wxMpMultiProperties.getConfigStorage().getKeyPrefix());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/WxMpInMemoryConfiguration.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/WxMpInMemoryConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.configuration.services;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpMultiProperties;
import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServices;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 自动装配基于内存策略配置
*
* @author yl
* created on 2024/1/23
*/
@Configuration
@ConditionalOnProperty(
prefix = WxMpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "memory", matchIfMissing = true
)
@RequiredArgsConstructor
public class WxMpInMemoryConfiguration extends AbstractWxMpConfiguration {
private final WxMpMultiProperties wxMpMultiProperties;
@Bean
public WxMpMultiServices wxMpMultiServices() {
return this.wxMpMultiServices(wxMpMultiProperties);
}
@Override
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
return this.configInMemory();
}
private WxMpDefaultConfigImpl configInMemory() {
return new WxMpMapConfigImpl();
// return new WxMpDefaultConfigImpl();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/AbstractWxMpConfiguration.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/AbstractWxMpConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.configuration.services;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpMultiProperties;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpSingleProperties;
import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServices;
import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServicesImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.*;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.WxMpHostConfig;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.apache.commons.lang3.StringUtils;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* WxMpConfigStorage 抽象配置类
*
* @author yl
* created on 2024/1/23
*/
@RequiredArgsConstructor
@Slf4j
public abstract class AbstractWxMpConfiguration {
protected WxMpMultiServices wxMpMultiServices(WxMpMultiProperties wxMpMultiProperties) {
Map<String, WxMpSingleProperties> appsMap = wxMpMultiProperties.getApps();
if (appsMap == null || appsMap.isEmpty()) {
log.warn("微信公众号应用参数未配置,通过 WxMpMultiServices#getWxMpService(\"tenantId\")获取实例将返回空");
return new WxMpMultiServicesImpl();
}
/**
* 校验 appId 是否唯一,避免使用 redis 缓存 token、ticket 时错乱。
*
* 查看 {@link me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl#setAppId(String)}
*/
Collection<WxMpSingleProperties> apps = appsMap.values();
if (apps.size() > 1) {
// 校验 appId 是否唯一
boolean multi = apps.stream()
// 没有 appId,如果不判断是否为空,这里会报 NPE 异常
.collect(Collectors.groupingBy(c -> c.getAppId() == null ? 0 : c.getAppId(), Collectors.counting()))
.entrySet().stream().anyMatch(e -> e.getValue() > 1);
if (multi) {
throw new RuntimeException("请确保微信公众号配置 appId 的唯一性");
}
}
WxMpMultiServicesImpl services = new WxMpMultiServicesImpl();
Set<Map.Entry<String, WxMpSingleProperties>> entries = appsMap.entrySet();
for (Map.Entry<String, WxMpSingleProperties> entry : entries) {
String tenantId = entry.getKey();
WxMpSingleProperties wxMpSingleProperties = entry.getValue();
WxMpDefaultConfigImpl storage = this.wxMpConfigStorage(wxMpMultiProperties);
this.configApp(storage, wxMpSingleProperties);
this.configHttp(storage, wxMpMultiProperties.getConfigStorage());
this.configHost(storage, wxMpMultiProperties.getHosts());
WxMpService wxMpService = this.wxMpService(storage, wxMpMultiProperties);
services.addWxMpService(tenantId, wxMpService);
}
return services;
}
/**
* 配置 WxMpDefaultConfigImpl
*
* @param wxMpMultiProperties 参数
* @return WxMpDefaultConfigImpl
*/
protected abstract WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties);
public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpMultiProperties wxMpMultiProperties) {
WxMpMultiProperties.ConfigStorage storage = wxMpMultiProperties.getConfigStorage();
WxMpMultiProperties.HttpClientType httpClientType = storage.getHttpClientType();
WxMpService wxMpService;
switch (httpClientType) {
case OK_HTTP:
wxMpService = new WxMpServiceOkHttpImpl();
break;
case JODD_HTTP:
wxMpService = new WxMpServiceJoddHttpImpl();
break;
case HTTP_CLIENT:
wxMpService = new WxMpServiceHttpClientImpl();
break;
case HTTP_COMPONENTS:
wxMpService = new WxMpServiceHttpComponentsImpl();
break;
default:
wxMpService = new WxMpServiceImpl();
break;
}
wxMpService.setWxMpConfigStorage(configStorage);
int maxRetryTimes = storage.getMaxRetryTimes();
if (maxRetryTimes < 0) {
maxRetryTimes = 0;
}
int retrySleepMillis = storage.getRetrySleepMillis();
if (retrySleepMillis < 0) {
retrySleepMillis = 1000;
}
wxMpService.setRetrySleepMillis(retrySleepMillis);
wxMpService.setMaxRetryTimes(maxRetryTimes);
return wxMpService;
}
private void configApp(WxMpDefaultConfigImpl config, WxMpSingleProperties corpProperties) {
String appId = corpProperties.getAppId();
String appSecret = corpProperties.getAppSecret();
String token = corpProperties.getToken();
String aesKey = corpProperties.getAesKey();
boolean useStableAccessToken = corpProperties.isUseStableAccessToken();
config.setAppId(appId);
config.setSecret(appSecret);
if (StringUtils.isNotBlank(token)) {
config.setToken(token);
}
if (StringUtils.isNotBlank(aesKey)) {
config.setAesKey(aesKey);
}
config.setUseStableAccessToken(useStableAccessToken);
}
private void configHttp(WxMpDefaultConfigImpl config, WxMpMultiProperties.ConfigStorage storage) {
String httpProxyHost = storage.getHttpProxyHost();
Integer httpProxyPort = storage.getHttpProxyPort();
String httpProxyUsername = storage.getHttpProxyUsername();
String httpProxyPassword = storage.getHttpProxyPassword();
if (StringUtils.isNotBlank(httpProxyHost)) {
config.setHttpProxyHost(httpProxyHost);
if (httpProxyPort != null) {
config.setHttpProxyPort(httpProxyPort);
}
if (StringUtils.isNotBlank(httpProxyUsername)) {
config.setHttpProxyUsername(httpProxyUsername);
}
if (StringUtils.isNotBlank(httpProxyPassword)) {
config.setHttpProxyPassword(httpProxyPassword);
}
}
}
/**
* wx host config
*/
private void configHost(WxMpDefaultConfigImpl config, WxMpMultiProperties.HostConfig hostConfig) {
if (hostConfig != null) {
String apiHost = hostConfig.getApiHost();
String mpHost = hostConfig.getMpHost();
String openHost = hostConfig.getOpenHost();
WxMpHostConfig wxMpHostConfig = new WxMpHostConfig();
wxMpHostConfig.setApiHost(StringUtils.isNotBlank(apiHost) ? apiHost : null);
wxMpHostConfig.setMpHost(StringUtils.isNotBlank(mpHost) ? mpHost : null);
wxMpHostConfig.setOpenHost(StringUtils.isNotBlank(openHost) ? openHost : null);
config.setHostConfig(wxMpHostConfig);
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/autoconfigure/WxMpMultiAutoConfiguration.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/autoconfigure/WxMpMultiAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.autoconfigure;
import com.binarywang.spring.starter.wxjava.mp.configuration.WxMpMultiServiceConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* @author yl
* created on 2024/1/23
*/
@Configuration
@Import(WxMpMultiServiceConfiguration.class)
public class WxMpMultiAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpSingleProperties.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpSingleProperties.java | package com.binarywang.spring.starter.wxjava.mp.properties;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author yl
* created on 2024/1/23
*/
@Data
@NoArgsConstructor
public class WxMpSingleProperties implements Serializable {
private static final long serialVersionUID = 1980986361098922525L;
/**
* 设置微信公众号的 appid.
*/
private String appId;
/**
* 设置微信公众号的 app secret.
*/
private String appSecret;
/**
* 设置微信公众号的 token.
*/
private String token;
/**
* 设置微信公众号的 EncodingAESKey.
*/
private String aesKey;
/**
* 是否使用稳定版 Access Token
*/
private boolean useStableAccessToken = false;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpMultiRedisProperties.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpMultiRedisProperties.java | package com.binarywang.spring.starter.wxjava.mp.properties;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author yl
* created on 2024/1/23
*/
@Data
@NoArgsConstructor
public class WxMpMultiRedisProperties implements Serializable {
private static final long serialVersionUID = -5924815351660074401L;
/**
* 主机地址.
*/
private String host = "127.0.0.1";
/**
* 端口号.
*/
private int port = 6379;
/**
* 密码.
*/
private String password;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 数据库.
*/
private int database = 0;
/**
* sentinel ips
*/
private String sentinelIps;
/**
* sentinel name
*/
private String sentinelName;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpMultiProperties.java | spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpMultiProperties.java | package com.binarywang.spring.starter.wxjava.mp.properties;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author yl
* created on 2024/1/23
*/
@Data
@NoArgsConstructor
@ConfigurationProperties(WxMpMultiProperties.PREFIX)
public class WxMpMultiProperties implements Serializable {
private static final long serialVersionUID = -5358245184407791011L;
public static final String PREFIX = "wx.mp";
private Map<String, WxMpSingleProperties> apps = new HashMap<>();
/**
* 自定义host配置
*/
private HostConfig hosts;
/**
* 存储策略
*/
private final ConfigStorage configStorage = new ConfigStorage();
@Data
@NoArgsConstructor
public static class HostConfig implements Serializable {
private static final long serialVersionUID = -4172767630740346001L;
/**
* 对应于:https://api.weixin.qq.com
*/
private String apiHost;
/**
* 对应于:https://open.weixin.qq.com
*/
private String openHost;
/**
* 对应于:https://mp.weixin.qq.com
*/
private String mpHost;
}
@Data
@NoArgsConstructor
public static class ConfigStorage implements Serializable {
private static final long serialVersionUID = 4815731027000065434L;
/**
* 存储类型.
*/
private StorageType type = StorageType.MEMORY;
/**
* 指定key前缀.
*/
private String keyPrefix = "wx:mp:multi";
/**
* redis连接配置.
*/
@NestedConfigurationProperty
private final WxMpMultiRedisProperties redis = new WxMpMultiRedisProperties();
/**
* http客户端类型.
*/
private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT;
/**
* http代理主机.
*/
private String httpProxyHost;
/**
* http代理端口.
*/
private Integer httpProxyPort;
/**
* http代理用户名.
*/
private String httpProxyUsername;
/**
* http代理密码.
*/
private String httpProxyPassword;
/**
* http 请求最大重试次数
* <pre>
* {@link me.chanjar.weixin.mp.api.WxMpService#setMaxRetryTimes(int)}
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
* </pre>
*/
private int maxRetryTimes = 5;
/**
* http 请求重试间隔
* <pre>
* {@link me.chanjar.weixin.mp.api.WxMpService#setRetrySleepMillis(int)}
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
* </pre>
*/
private int retrySleepMillis = 1000;
}
public enum StorageType {
/**
* 内存
*/
MEMORY,
/**
* jedis
*/
JEDIS,
/**
* redisson
*/
REDISSON,
/**
* redisTemplate
*/
REDIS_TEMPLATE
}
public enum HttpClientType {
/**
* HttpClient
*/
HTTP_CLIENT,
/**
* HttpComponents
*/
HTTP_COMPONENTS,
/**
* OkHttp
*/
OK_HTTP,
/**
* JoddHttp
*/
JODD_HTTP
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenProperties.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenProperties.java | package com.binarywang.spring.starter.wxjava.open.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.io.Serializable;
import static com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties.PREFIX;
import static com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties.StorageType.memory;
/**
* 微信接入相关配置属性.
*
* @author someone
*/
@Data
@ConfigurationProperties(PREFIX)
public class WxOpenProperties {
public static final String PREFIX = "wx.open";
/**
* 设置微信开放平台的appid.
*/
private String appId;
/**
* 设置微信开放平台的app secret.
*/
private String secret;
/**
* 设置微信开放平台的token.
*/
private String token;
/**
* 设置微信开放平台的EncodingAESKey.
*/
private String aesKey;
/**
* 自定义API主机地址,用于替换默认的 https://api.weixin.qq.com
* 例如:http://proxy.company.com:8080
*/
private String apiHostUrl;
/**
* 自定义获取AccessToken地址,用于向自定义统一服务获取AccessToken
* 例如:http://proxy.company.com:8080/oauth/token
*/
private String accessTokenUrl;
/**
* 存储策略.
*/
private ConfigStorage configStorage = new ConfigStorage();
@Data
public static class ConfigStorage implements Serializable {
private static final long serialVersionUID = 4815731027000065434L;
/**
* 存储类型.
*/
private StorageType type = memory;
/**
* 指定key前缀.
*/
private String keyPrefix = "wx:open";
/**
* redis连接配置.
*/
@NestedConfigurationProperty
private WxOpenRedisProperties redis = new WxOpenRedisProperties();
/**
* http客户端类型.
*/
private HttpClientType httpClientType = HttpClientType.httpclient;
/**
* http代理主机.
*/
private String httpProxyHost;
/**
* http代理端口.
*/
private Integer httpProxyPort;
/**
* http代理用户名.
*/
private String httpProxyUsername;
/**
* http代理密码.
*/
private String httpProxyPassword;
/**
* http 请求重试间隔
* <pre>
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setRetrySleepMillis(int)}
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
* </pre>
*/
private int retrySleepMillis = 1000;
/**
* http 请求最大重试次数
* <pre>
* {@link me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl#setMaxRetryTimes(int)}
* {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
* </pre>
*/
private int maxRetryTimes = 5;
/**
* 连接超时时间,单位毫秒
*/
private int connectionTimeout = 5000;
/**
* 读数据超时时间,即socketTimeout,单位毫秒
*/
private int soTimeout = 5000;
/**
* 从连接池获取链接的超时时间,单位毫秒
*/
private int connectionRequestTimeout = 5000;
}
public enum StorageType {
/**
* 内存.
*/
memory,
/**
* jedis.
*/
jedis,
/**
* redisson.
*/
redisson,
/**
* redistemplate
*/
redistemplate
}
public enum HttpClientType {
/**
* HttpClient.
*/
httpclient
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenRedisProperties.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/properties/WxOpenRedisProperties.java | package com.binarywang.spring.starter.wxjava.open.properties;
import lombok.Data;
import java.io.Serializable;
/**
* Redis配置.
*
* @author someone
*/
@Data
public class WxOpenRedisProperties implements Serializable {
private static final long serialVersionUID = -5924815351660074401L;
/**
* 主机地址.
*/
private String host;
/**
* 端口号.
*/
private int port = 6379;
/**
* 密码.
*/
private String password;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 数据库.
*/
private int database = 0;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenServiceAutoConfiguration.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenServiceAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.open.config;
import me.chanjar.weixin.open.api.WxOpenComponentService;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.api.WxOpenService;
import me.chanjar.weixin.open.api.impl.WxOpenMessageRouter;
import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 微信开放平台相关服务自动注册.
*
* @author someone
*/
@Configuration
public class WxOpenServiceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(WxOpenConfigStorage.class)
public WxOpenService wxOpenService(WxOpenConfigStorage wxOpenConfigStorage) {
WxOpenService wxOpenService = new WxOpenServiceImpl();
wxOpenService.setWxOpenConfigStorage(wxOpenConfigStorage);
return wxOpenService;
}
@Bean
@ConditionalOnMissingBean
public WxOpenMessageRouter wxOpenMessageRouter(WxOpenService wxOpenService) {
return new WxOpenMessageRouter(wxOpenService);
}
@Bean
public WxOpenComponentService wxOpenComponentService(WxOpenService wxOpenService) {
return wxOpenService.getWxOpenComponentService();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenAutoConfiguration.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.open.config;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* .
*
* @author someone
*/
@Configuration
@EnableConfigurationProperties(WxOpenProperties.class)
@Import({
WxOpenStorageAutoConfiguration.class,
WxOpenServiceAutoConfiguration.class
})
public class WxOpenAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenStorageAutoConfiguration.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenStorageAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.open.config;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInJedisConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInMemoryConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedisTemplateConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.open.config.storage.WxOpenInRedissonConfigStorageConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* 微信公众号存储策略自动配置.
*
* @author someone
*/
@Configuration
@Import({
WxOpenInMemoryConfigStorageConfiguration.class,
WxOpenInRedisTemplateConfigStorageConfiguration.class,
WxOpenInJedisConfigStorageConfiguration.class,
WxOpenInRedissonConfigStorageConfiguration.class
})
public class WxOpenStorageAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInMemoryConfigStorageConfiguration.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInMemoryConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.open.config.storage;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author yl
*/
@Configuration
@ConditionalOnProperty(
prefix = WxOpenProperties.PREFIX + ".config-storage", name = "type",
matchIfMissing = true, havingValue = "memory"
)
@RequiredArgsConstructor
public class WxOpenInMemoryConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
private final WxOpenProperties properties;
@Bean
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
return this.config(config, properties);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/AbstractWxOpenConfigStorageConfiguration.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/AbstractWxOpenConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.open.config.storage;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
import org.apache.commons.lang3.StringUtils;
/**
* @author yl
*/
public abstract class AbstractWxOpenConfigStorageConfiguration {
protected WxOpenInMemoryConfigStorage config(WxOpenInMemoryConfigStorage config, WxOpenProperties properties) {
WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
config.setWxOpenInfo(properties.getAppId(), properties.getSecret(), properties.getToken(), properties.getAesKey());
config.setHttpProxyHost(storage.getHttpProxyHost());
config.setHttpProxyUsername(storage.getHttpProxyUsername());
config.setHttpProxyPassword(storage.getHttpProxyPassword());
Integer httpProxyPort = storage.getHttpProxyPort();
if (httpProxyPort != null) {
config.setHttpProxyPort(httpProxyPort);
}
int maxRetryTimes = storage.getMaxRetryTimes();
if (maxRetryTimes < 0) {
maxRetryTimes = 0;
}
int retrySleepMillis = storage.getRetrySleepMillis();
if (retrySleepMillis < 0) {
retrySleepMillis = 1000;
}
config.setRetrySleepMillis(retrySleepMillis);
config.setMaxRetryTimes(maxRetryTimes);
// 设置URL配置
config.setApiHostUrl(StringUtils.trimToNull(properties.getApiHostUrl()));
config.setAccessTokenUrl(StringUtils.trimToNull(properties.getAccessTokenUrl()));
// 设置自定义的HttpClient超时配置
ApacheHttpClientBuilder clientBuilder = config.getApacheHttpClientBuilder();
if (clientBuilder == null) {
clientBuilder = DefaultApacheHttpClientBuilder.get();
}
if (clientBuilder instanceof DefaultApacheHttpClientBuilder) {
DefaultApacheHttpClientBuilder defaultBuilder = (DefaultApacheHttpClientBuilder) clientBuilder;
defaultBuilder.setConnectionTimeout(storage.getConnectionTimeout());
defaultBuilder.setSoTimeout(storage.getSoTimeout());
defaultBuilder.setConnectionRequestTimeout(storage.getConnectionRequestTimeout());
config.setApacheHttpClientBuilder(defaultBuilder);
}
return config;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInJedisConfigStorageConfiguration.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInJedisConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.open.config.storage;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenRedisProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenInRedisConfigStorage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* @author yl
*/
@Configuration
@ConditionalOnProperty(
prefix = WxOpenProperties.PREFIX + ".config-storage", name = "type", havingValue = "jedis"
)
@ConditionalOnClass({JedisPool.class, JedisPoolConfig.class})
@RequiredArgsConstructor
public class WxOpenInJedisConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
private final WxOpenProperties properties;
private final ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenInMemoryConfigStorage config = getWxOpenInRedisConfigStorage();
return this.config(config, properties);
}
private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() {
WxOpenRedisProperties wxOpenRedisProperties = properties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (wxOpenRedisProperties != null && StringUtils.isNotEmpty(wxOpenRedisProperties.getHost())) {
jedisPool = getJedisPool();
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
return new WxOpenInRedisConfigStorage(jedisPool, properties.getConfigStorage().getKeyPrefix());
}
private JedisPool getJedisPool() {
WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
WxOpenRedisProperties redis = storage.getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
return new JedisPool(config, redis.getHost(), redis.getPort(),
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedissonConfigStorageConfiguration.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedissonConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.open.config.storage;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenRedisProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenInRedissonConfigStorage;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author yl
*/
@Configuration
@ConditionalOnProperty(
prefix = WxOpenProperties.PREFIX + ".config-storage", name = "type", havingValue = "redisson"
)
@ConditionalOnClass({Redisson.class, RedissonClient.class})
@RequiredArgsConstructor
public class WxOpenInRedissonConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
private final WxOpenProperties properties;
private final ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenInMemoryConfigStorage config = getWxOpenInRedissonConfigStorage();
return this.config(config, properties);
}
private WxOpenInRedissonConfigStorage getWxOpenInRedissonConfigStorage() {
WxOpenRedisProperties wxOpenRedisProperties = properties.getConfigStorage().getRedis();
RedissonClient redissonClient;
if (wxOpenRedisProperties != null && StringUtils.isNotEmpty(wxOpenRedisProperties.getHost())) {
redissonClient = getRedissonClient();
} else {
redissonClient = applicationContext.getBean(RedissonClient.class);
}
return new WxOpenInRedissonConfigStorage(redissonClient, properties.getConfigStorage().getKeyPrefix());
}
private RedissonClient getRedissonClient() {
WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
WxOpenRedisProperties redis = storage.getRedis();
Config config = new Config();
config.useSingleServer()
.setAddress("redis://" + redis.getHost() + ":" + redis.getPort())
.setDatabase(redis.getDatabase())
.setPassword(redis.getPassword());
config.setTransportMode(TransportMode.NIO);
return Redisson.create(config);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisTemplateConfigStorageConfiguration.java | spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/storage/WxOpenInRedisTemplateConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.open.config.storage;
import com.binarywang.spring.starter.wxjava.open.properties.WxOpenProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenInRedisTemplateConfigStorage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
/**
* @author yl
*/
@Configuration
@ConditionalOnProperty(
prefix = WxOpenProperties.PREFIX + ".config-storage", name = "type", havingValue = "redistemplate"
)
@ConditionalOnClass(StringRedisTemplate.class)
@RequiredArgsConstructor
public class WxOpenInRedisTemplateConfigStorageConfiguration extends AbstractWxOpenConfigStorageConfiguration {
private final WxOpenProperties properties;
private final ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean(WxOpenConfigStorage.class)
public WxOpenConfigStorage wxOpenConfigStorage() {
WxOpenInMemoryConfigStorage config = getWxOpenInRedisTemplateConfigStorage();
return this.config(config, properties);
}
private WxOpenInRedisTemplateConfigStorage getWxOpenInRedisTemplateConfigStorage() {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
return new WxOpenInRedisTemplateConfigStorage(redisTemplate, properties.getConfigStorage().getKeyPrefix());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/properties/RedisProperties.java | spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/properties/RedisProperties.java | package com.binarywang.spring.starter.wxjava.qidian.properties;
import lombok.Data;
import java.io.Serializable;
/**
* redis 配置属性.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2020-08-30
*/
@Data
public class RedisProperties implements Serializable {
private static final long serialVersionUID = -5924815351660074401L;
/**
* 主机地址.
*/
private String host = "127.0.0.1";
/**
* 端口号.
*/
private int port = 6379;
/**
* 密码.
*/
private String password;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 数据库.
*/
private int database = 0;
/**
* sentinel ips
*/
private String sentinelIps;
/**
* sentinel name
*/
private String sentinelName;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/properties/HostConfig.java | spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/properties/HostConfig.java | package com.binarywang.spring.starter.wxjava.qidian.properties;
import lombok.Data;
import java.io.Serializable;
@Data
public class HostConfig implements Serializable {
private static final long serialVersionUID = -4172767630740346001L;
private String apiHost;
private String openHost;
private String qidianHost;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/properties/WxQidianProperties.java | spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/properties/WxQidianProperties.java | package com.binarywang.spring.starter.wxjava.qidian.properties;
import com.binarywang.spring.starter.wxjava.qidian.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.qidian.enums.StorageType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.io.Serializable;
import static com.binarywang.spring.starter.wxjava.qidian.enums.StorageType.Memory;
import static com.binarywang.spring.starter.wxjava.qidian.properties.WxQidianProperties.PREFIX;
/**
* 企点接入相关配置属性.
*
* @author someone
*/
@Data
@ConfigurationProperties(PREFIX)
public class WxQidianProperties {
public static final String PREFIX = "wx.qidian";
/**
* 设置腾讯企点的appid.
*/
private String appId;
/**
* 设置腾讯企点的app secret.
*/
private String secret;
/**
* 设置腾讯企点的token.
*/
private String token;
/**
* 设置腾讯企点的EncodingAESKey.
*/
private String aesKey;
/**
* 自定义host配置
*/
private HostConfig hosts;
/**
* 存储策略
*/
private ConfigStorage configStorage = new ConfigStorage();
@Data
public static class ConfigStorage implements Serializable {
private static final long serialVersionUID = 4815731027000065434L;
/**
* 存储类型.
*/
private StorageType type = Memory;
/**
* 指定key前缀.
*/
private String keyPrefix = "wx";
/**
* redis连接配置.
*/
private RedisProperties redis = new RedisProperties();
/**
* http客户端类型.
*/
private HttpClientType httpClientType = HttpClientType.HttpClient;
/**
* http代理主机.
*/
private String httpProxyHost;
/**
* http代理端口.
*/
private Integer httpProxyPort;
/**
* http代理用户名.
*/
private String httpProxyUsername;
/**
* http代理密码.
*/
private String httpProxyPassword;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/config/WxQidianStorageAutoConfiguration.java | spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/config/WxQidianStorageAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.qidian.config;
import com.binarywang.spring.starter.wxjava.qidian.enums.StorageType;
import com.binarywang.spring.starter.wxjava.qidian.properties.RedisProperties;
import com.binarywang.spring.starter.wxjava.qidian.properties.WxQidianProperties;
import com.google.common.collect.Sets;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import me.chanjar.weixin.qidian.bean.WxQidianHostConfig;
import me.chanjar.weixin.qidian.config.WxQidianConfigStorage;
import me.chanjar.weixin.qidian.config.impl.WxQidianDefaultConfigImpl;
import me.chanjar.weixin.qidian.config.impl.WxQidianRedisConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;
import redis.clients.jedis.util.Pool;
import java.util.Set;
/**
* 腾讯企点存储策略自动配置.
*
* @author alegria
*/
@Slf4j
@Configuration
@RequiredArgsConstructor
public class WxQidianStorageAutoConfiguration {
private final ApplicationContext applicationContext;
private final WxQidianProperties wxQidianProperties;
@Value("${wx.mp.config-storage.redis.host:")
private String redisHost;
@Value("${wx.mp.configStorage.redis.host:")
private String redisHost2;
@Bean
@ConditionalOnMissingBean(WxQidianConfigStorage.class)
public WxQidianConfigStorage wxQidianConfigStorage() {
StorageType type = wxQidianProperties.getConfigStorage().getType();
WxQidianConfigStorage config;
switch (type) {
case Jedis:
config = jedisConfigStorage();
break;
case RedisTemplate:
config = redisTemplateConfigStorage();
break;
default:
config = defaultConfigStorage();
break;
}
// wx host config
if (null != wxQidianProperties.getHosts() && StringUtils.isNotEmpty(wxQidianProperties.getHosts().getApiHost())) {
WxQidianHostConfig hostConfig = new WxQidianHostConfig();
hostConfig.setApiHost(wxQidianProperties.getHosts().getApiHost());
hostConfig.setQidianHost(wxQidianProperties.getHosts().getQidianHost());
hostConfig.setOpenHost(wxQidianProperties.getHosts().getOpenHost());
config.setHostConfig(hostConfig);
}
return config;
}
private WxQidianConfigStorage defaultConfigStorage() {
WxQidianDefaultConfigImpl config = new WxQidianDefaultConfigImpl();
setWxMpInfo(config);
return config;
}
private WxQidianConfigStorage jedisConfigStorage() {
Pool<Jedis> jedisPool;
if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) {
jedisPool = getJedisPool();
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
WxQidianRedisConfigImpl wxQidianRedisConfig = new WxQidianRedisConfigImpl(redisOps,
wxQidianProperties.getConfigStorage().getKeyPrefix());
setWxMpInfo(wxQidianRedisConfig);
return wxQidianRedisConfig;
}
private WxQidianConfigStorage redisTemplateConfigStorage() {
StringRedisTemplate redisTemplate = null;
try {
redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
try {
if (null == redisTemplate) {
redisTemplate = (StringRedisTemplate) applicationContext.getBean("stringRedisTemplate");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
if (null == redisTemplate) {
redisTemplate = (StringRedisTemplate) applicationContext.getBean("redisTemplate");
}
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
WxQidianRedisConfigImpl wxMpRedisConfig = new WxQidianRedisConfigImpl(redisOps,
wxQidianProperties.getConfigStorage().getKeyPrefix());
setWxMpInfo(wxMpRedisConfig);
return wxMpRedisConfig;
}
private void setWxMpInfo(WxQidianDefaultConfigImpl config) {
WxQidianProperties properties = wxQidianProperties;
WxQidianProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setAppId(properties.getAppId());
config.setSecret(properties.getSecret());
config.setToken(properties.getToken());
config.setAesKey(properties.getAesKey());
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
}
private Pool<Jedis> getJedisPool() {
WxQidianProperties.ConfigStorage storage = wxQidianProperties.getConfigStorage();
RedisProperties redis = storage.getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
if (StringUtils.isNotEmpty(redis.getSentinelIps())) {
Set<String> sentinels = Sets.newHashSet(redis.getSentinelIps().split(","));
return new JedisSentinelPool(redis.getSentinelName(), sentinels,config);
}
return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
redis.getDatabase());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/config/WxQidianAutoConfiguration.java | spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/config/WxQidianAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.qidian.config;
import com.binarywang.spring.starter.wxjava.qidian.properties.WxQidianProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* .
*
* @author someone
*/
@Configuration
@EnableConfigurationProperties(WxQidianProperties.class)
@Import({ WxQidianStorageAutoConfiguration.class, WxQidianServiceAutoConfiguration.class })
public class WxQidianAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/config/WxQidianServiceAutoConfiguration.java | spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/config/WxQidianServiceAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.qidian.config;
import com.binarywang.spring.starter.wxjava.qidian.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.qidian.properties.WxQidianProperties;
import me.chanjar.weixin.qidian.api.WxQidianService;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceHttpClientImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceJoddHttpImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceOkHttpImpl;
import me.chanjar.weixin.qidian.config.WxQidianConfigStorage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 腾讯企点相关服务自动注册.
*
* @author alegria
*/
@Configuration
public class WxQidianServiceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public WxQidianService wxQidianService(WxQidianConfigStorage configStorage, WxQidianProperties wxQidianProperties) {
HttpClientType httpClientType = wxQidianProperties.getConfigStorage().getHttpClientType();
WxQidianService wxQidianService;
switch (httpClientType) {
case OkHttp:
wxQidianService = newWxQidianServiceOkHttpImpl();
break;
case JoddHttp:
wxQidianService = newWxQidianServiceJoddHttpImpl();
break;
case HttpClient:
wxQidianService = newWxQidianServiceHttpClientImpl();
break;
default:
wxQidianService = newWxQidianServiceImpl();
break;
}
wxQidianService.setWxMpConfigStorage(configStorage);
return wxQidianService;
}
private WxQidianService newWxQidianServiceImpl() {
return new WxQidianServiceImpl();
}
private WxQidianService newWxQidianServiceHttpClientImpl() {
return new WxQidianServiceHttpClientImpl();
}
private WxQidianService newWxQidianServiceOkHttpImpl() {
return new WxQidianServiceOkHttpImpl();
}
private WxQidianService newWxQidianServiceJoddHttpImpl() {
return new WxQidianServiceJoddHttpImpl();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/enums/HttpClientType.java | spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/enums/HttpClientType.java | package com.binarywang.spring.starter.wxjava.qidian.enums;
/**
* httpclient类型.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2020-08-30
*/
public enum HttpClientType {
/**
* HttpClient.
*/
HttpClient,
/**
* OkHttp.
*/
OkHttp,
/**
* JoddHttp.
*/
JoddHttp,
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/enums/StorageType.java | spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/enums/StorageType.java | package com.binarywang.spring.starter.wxjava.qidian.enums;
/**
* storage类型.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2020-08-30
*/
public enum StorageType {
/**
* 内存.
*/
Memory,
/**
* redis(JedisClient).
*/
Jedis,
/**
* redis(Redisson).
*/
Redisson,
/**
* redis(RedisTemplate).
*/
RedisTemplate
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/service/WxCpTpMultiServices.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/service/WxCpTpMultiServices.java | package com.binarywang.spring.starter.wxjava.cp.service;
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
/**
* 企业微信 {@link WxCpTpService} 所有实例存放类.
*
* @author yl
* created on 2023/10/16
*/
public interface WxCpTpMultiServices {
/**
* 通过租户 Id 获取 WxCpTpService
*
* @param tenantId 租户 Id
* @return WxCpTpService
*/
WxCpTpService getWxCpTpService(String tenantId);
void addWxCpTpService(String tenantId, WxCpTpService wxCpService);
/**
* 根据租户 Id,从列表中移除一个 WxCpTpService 实例
*
* @param tenantId 租户 Id
*/
void removeWxCpTpService(String tenantId);
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/service/WxCpTpMultiServicesImpl.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/service/WxCpTpMultiServicesImpl.java | package com.binarywang.spring.starter.wxjava.cp.service;
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 企业微信 {@link WxCpTpMultiServices} 默认实现
*
* @author yl
* created on 2023/10/16
*/
public class WxCpTpMultiServicesImpl implements WxCpTpMultiServices {
private final Map<String, WxCpTpService> services = new ConcurrentHashMap<>();
/**
* 通过租户 Id 获取 WxCpTpService
*
* @param tenantId 租户 Id
* @return WxCpTpService
*/
@Override
public WxCpTpService getWxCpTpService(String tenantId) {
return this.services.get(tenantId);
}
/**
* 根据租户 Id,添加一个 WxCpTpService 到列表
*
* @param tenantId 租户 Id
* @param wxCpService WxCpTpService 实例
*/
@Override
public void addWxCpTpService(String tenantId, WxCpTpService wxCpService) {
this.services.put(tenantId, wxCpService);
}
@Override
public void removeWxCpTpService(String tenantId) {
this.services.remove(tenantId);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/WxCpTpMultiServicesAutoConfiguration.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/WxCpTpMultiServicesAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.cp.configuration;
import com.binarywang.spring.starter.wxjava.cp.configuration.services.WxCpTpInJedisTpConfiguration;
import com.binarywang.spring.starter.wxjava.cp.configuration.services.WxCpTpInMemoryTpConfiguration;
import com.binarywang.spring.starter.wxjava.cp.configuration.services.WxCpTpInRedisTemplateTpConfiguration;
import com.binarywang.spring.starter.wxjava.cp.configuration.services.WxCpTpInRedissonTpConfiguration;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* 企业微信平台相关服务自动注册
*
* @author yl
* created on 2023/10/16
*/
@Configuration
@EnableConfigurationProperties(WxCpTpMultiProperties.class)
@Import({
WxCpTpInJedisTpConfiguration.class,
WxCpTpInMemoryTpConfiguration.class,
WxCpTpInRedissonTpConfiguration.class,
WxCpTpInRedisTemplateTpConfiguration.class
})
public class WxCpTpMultiServicesAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/AbstractWxCpTpConfiguration.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/AbstractWxCpTpConfiguration.java | package com.binarywang.spring.starter.wxjava.cp.configuration.services;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpSingleProperties;
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServicesImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceApacheHttpClientImpl;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceImpl;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceJoddHttpImpl;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceOkHttpImpl;
import org.apache.commons.lang3.StringUtils;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* WxCpConfigStorage 抽象配置类
*
* @author yl
* created on 2023/10/16
*/
@RequiredArgsConstructor
@Slf4j
public abstract class AbstractWxCpTpConfiguration {
/**
*
* @param wxCpTpMultiProperties 应用列表配置
* @param services 用于支持,应用启动之后,可以调用这个接口添加新服务对象。主要是配置是从数据库中读取的
* @return
*/
public WxCpTpMultiServices wxCpMultiServices(WxCpTpMultiProperties wxCpTpMultiProperties,WxCpTpMultiServices services) {
Map<String, WxCpTpSingleProperties> corps = wxCpTpMultiProperties.getCorps();
if (corps == null || corps.isEmpty()) {
log.warn("企业微信应用参数未配置,通过 WxCpMultiServices#getWxCpTpService(\"tenantId\")获取实例将返回空");
return new WxCpTpMultiServicesImpl();
}
if (services == null) {
services = new WxCpTpMultiServicesImpl();
}
Set<Map.Entry<String, WxCpTpSingleProperties>> entries = corps.entrySet();
for (Map.Entry<String, WxCpTpSingleProperties> entry : entries) {
String tenantId = entry.getKey();
WxCpTpSingleProperties wxCpTpSingleProperties = entry.getValue();
WxCpTpDefaultConfigImpl storage = this.wxCpTpConfigStorage(wxCpTpMultiProperties);
this.configCorp(storage, wxCpTpSingleProperties);
this.configHttp(storage, wxCpTpMultiProperties.getConfigStorage());
WxCpTpService wxCpTpService = this.wxCpTpService(storage, wxCpTpMultiProperties.getConfigStorage());
if (services.getWxCpTpService(tenantId) == null) {
// 不存在的才会添加到服务列表中
services.addWxCpTpService(tenantId, wxCpTpService);
}
}
return services;
}
/**
* 配置 WxCpDefaultConfigImpl
*
* @param wxCpTpMultiProperties 参数
* @return WxCpDefaultConfigImpl
*/
protected abstract WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties);
private WxCpTpService wxCpTpService(WxCpTpConfigStorage wxCpTpConfigStorage, WxCpTpMultiProperties.ConfigStorage storage) {
WxCpTpMultiProperties.HttpClientType httpClientType = storage.getHttpClientType();
WxCpTpService cpTpService;
switch (httpClientType) {
case OK_HTTP:
cpTpService = new WxCpTpServiceOkHttpImpl();
break;
case JODD_HTTP:
cpTpService = new WxCpTpServiceJoddHttpImpl();
break;
case HTTP_CLIENT:
cpTpService = new WxCpTpServiceApacheHttpClientImpl();
break;
default:
cpTpService = new WxCpTpServiceImpl();
break;
}
cpTpService.setWxCpTpConfigStorage(wxCpTpConfigStorage);
int maxRetryTimes = storage.getMaxRetryTimes();
if (maxRetryTimes < 0) {
maxRetryTimes = 0;
}
int retrySleepMillis = storage.getRetrySleepMillis();
if (retrySleepMillis < 0) {
retrySleepMillis = 1000;
}
cpTpService.setRetrySleepMillis(retrySleepMillis);
cpTpService.setMaxRetryTimes(maxRetryTimes);
return cpTpService;
}
private void configCorp(WxCpTpDefaultConfigImpl config, WxCpTpSingleProperties wxCpTpSingleProperties) {
String corpId = wxCpTpSingleProperties.getCorpId();
String providerSecret = wxCpTpSingleProperties.getProviderSecret();
String suiteId = wxCpTpSingleProperties.getSuiteId();
String token = wxCpTpSingleProperties.getToken();
String suiteSecret = wxCpTpSingleProperties.getSuiteSecret();
// 企业微信,私钥,会话存档路径
config.setCorpId(corpId);
config.setProviderSecret(providerSecret);
config.setEncodingAESKey(wxCpTpSingleProperties.getEncodingAESKey());
config.setSuiteId(suiteId);
config.setToken(token);
config.setSuiteSecret(suiteSecret);
}
private void configHttp(WxCpTpDefaultConfigImpl config, WxCpTpMultiProperties.ConfigStorage storage) {
String httpProxyHost = storage.getHttpProxyHost();
Integer httpProxyPort = storage.getHttpProxyPort();
String httpProxyUsername = storage.getHttpProxyUsername();
String httpProxyPassword = storage.getHttpProxyPassword();
if (StringUtils.isNotBlank(httpProxyHost)) {
config.setHttpProxyHost(httpProxyHost);
if (httpProxyPort != null) {
config.setHttpProxyPort(httpProxyPort);
}
if (StringUtils.isNotBlank(httpProxyUsername)) {
config.setHttpProxyUsername(httpProxyUsername);
}
if (StringUtils.isNotBlank(httpProxyPassword)) {
config.setHttpProxyPassword(httpProxyPassword);
}
}
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/WxCpTpInRedisTemplateTpConfiguration.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/WxCpTpInRedisTemplateTpConfiguration.java | package com.binarywang.spring.starter.wxjava.cp.configuration.services;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpRedisTemplateConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpTpRedisTemplateConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
/**
* 自动装配基于 redisTemplate 策略配置
*
* @author yl
* created on 2023/10/16
*/
@Configuration
@ConditionalOnProperty(
prefix = WxCpTpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "redistemplate"
)
@RequiredArgsConstructor
public class WxCpTpInRedisTemplateTpConfiguration extends AbstractWxCpTpConfiguration {
private final WxCpTpMultiProperties wxCpTpMultiProperties;
private final ApplicationContext applicationContext;
@Bean
public WxCpTpMultiServices wxCpMultiServices() {
return this.wxCpMultiServices(wxCpTpMultiProperties,null);
}
@Override
protected WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties) {
return this.configRedisTemplate(wxCpTpMultiProperties);
}
private WxCpTpDefaultConfigImpl configRedisTemplate(WxCpTpMultiProperties wxCpTpMultiProperties) {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
return new WxCpTpRedisTemplateConfigImpl(redisTemplate, wxCpTpMultiProperties.getConfigStorage().getKeyPrefix());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/WxCpTpInRedissonTpConfiguration.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/WxCpTpInRedissonTpConfiguration.java | package com.binarywang.spring.starter.wxjava.cp.configuration.services;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiRedisProperties;
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import me.chanjar.weixin.cp.config.impl.AbstractWxCpTpInRedisConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpTpRedissonConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 自动装配基于 redisson 策略配置
*
* @author yl
* created on 2023/10/16
*/
@Configuration
@ConditionalOnProperty(
prefix = WxCpTpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "redisson"
)
@RequiredArgsConstructor
public class WxCpTpInRedissonTpConfiguration extends AbstractWxCpTpConfiguration {
private final WxCpTpMultiProperties wxCpTpMultiProperties;
private final ApplicationContext applicationContext;
@Bean
public WxCpTpMultiServices wxCpMultiServices() {
return this.wxCpMultiServices(wxCpTpMultiProperties,null);
}
@Override
protected WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties) {
return this.configRedisson(wxCpTpMultiProperties);
}
private WxCpTpDefaultConfigImpl configRedisson(WxCpTpMultiProperties wxCpTpMultiProperties) {
WxCpTpMultiRedisProperties redisProperties = wxCpTpMultiProperties.getConfigStorage().getRedis();
RedissonClient redissonClient;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
redissonClient = getRedissonClient(wxCpTpMultiProperties);
} else {
redissonClient = applicationContext.getBean(RedissonClient.class);
}
return new WxCpTpRedissonConfigImpl(redissonClient, wxCpTpMultiProperties.getConfigStorage().getKeyPrefix());
}
private RedissonClient getRedissonClient(WxCpTpMultiProperties wxCpTpMultiProperties) {
WxCpTpMultiProperties.ConfigStorage storage = wxCpTpMultiProperties.getConfigStorage();
WxCpTpMultiRedisProperties redis = storage.getRedis();
Config config = new Config();
config.useSingleServer()
.setAddress("redis://" + redis.getHost() + ":" + redis.getPort())
.setDatabase(redis.getDatabase())
.setPassword(redis.getPassword());
config.setTransportMode(TransportMode.NIO);
return Redisson.create(config);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/WxCpTpInJedisTpConfiguration.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/WxCpTpInJedisTpConfiguration.java | package com.binarywang.spring.starter.wxjava.cp.configuration.services;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiRedisProperties;
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpJedisConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpTpJedisConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* 自动装配基于 jedis 策略配置
*
* @author yl
* created on 2023/10/16
*/
@Configuration
@ConditionalOnProperty(
prefix = WxCpTpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "jedis"
)
@RequiredArgsConstructor
public class WxCpTpInJedisTpConfiguration extends AbstractWxCpTpConfiguration {
private final WxCpTpMultiProperties wxCpTpMultiProperties;
private final ApplicationContext applicationContext;
@Bean
public WxCpTpMultiServices wxCpMultiServices() {
return this.wxCpMultiServices(wxCpTpMultiProperties,null);
}
@Override
protected WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties) {
return this.configRedis(wxCpTpMultiProperties);
}
private WxCpTpDefaultConfigImpl configRedis(WxCpTpMultiProperties wxCpTpMultiProperties) {
WxCpTpMultiRedisProperties wxCpTpMultiRedisProperties = wxCpTpMultiProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (wxCpTpMultiRedisProperties != null && StringUtils.isNotEmpty(wxCpTpMultiRedisProperties.getHost())) {
jedisPool = getJedisPool(wxCpTpMultiProperties);
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
return new WxCpTpJedisConfigImpl(jedisPool, wxCpTpMultiProperties.getConfigStorage().getKeyPrefix());
}
private JedisPool getJedisPool(WxCpTpMultiProperties wxCpTpMultiProperties) {
WxCpTpMultiProperties.ConfigStorage storage = wxCpTpMultiProperties.getConfigStorage();
WxCpTpMultiRedisProperties redis = storage.getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
return new JedisPool(config, redis.getHost(), redis.getPort(),
redis.getTimeout(), redis.getPassword(), redis.getDatabase());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/WxCpTpInMemoryTpConfiguration.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/configuration/services/WxCpTpInMemoryTpConfiguration.java | package com.binarywang.spring.starter.wxjava.cp.configuration.services;
import com.binarywang.spring.starter.wxjava.cp.properties.WxCpTpMultiProperties;
import com.binarywang.spring.starter.wxjava.cp.service.WxCpTpMultiServices;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 自动装配基于内存策略配置
*
* @author yl
* created on 2023/10/16
*/
@Configuration
@ConditionalOnProperty(
prefix = WxCpTpMultiProperties.PREFIX + ".config-storage", name = "type", havingValue = "memory", matchIfMissing = true
)
@RequiredArgsConstructor
public class WxCpTpInMemoryTpConfiguration extends AbstractWxCpTpConfiguration {
private final WxCpTpMultiProperties wxCpTpMultiProperties;
@Bean
public WxCpTpMultiServices wxCpMultiServices() {
return this.wxCpMultiServices(wxCpTpMultiProperties,null);
}
@Override
protected WxCpTpDefaultConfigImpl wxCpTpConfigStorage(WxCpTpMultiProperties wxCpTpMultiProperties) {
return this.configInMemory();
}
private WxCpTpDefaultConfigImpl configInMemory() {
return new WxCpTpDefaultConfigImpl();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/autoconfigure/WxCpTpMultiAutoConfiguration.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/autoconfigure/WxCpTpMultiAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.cp.autoconfigure;
import com.binarywang.spring.starter.wxjava.cp.configuration.WxCpTpMultiServicesAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* 企业微信自动注册
*
* @author yl
* created on 2023/10/16
*/
@Configuration
@Import(WxCpTpMultiServicesAutoConfiguration.class)
public class WxCpTpMultiAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/properties/WxCpTpMultiProperties.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/properties/WxCpTpMultiProperties.java | package com.binarywang.spring.starter.wxjava.cp.properties;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* 企业微信多企业接入相关配置属性
*
* @author yl
* created on 2023/10/16
*/
@Data
@NoArgsConstructor
@ConfigurationProperties(prefix = WxCpTpMultiProperties.PREFIX)
public class WxCpTpMultiProperties implements Serializable {
private static final long serialVersionUID = -1569510477055668503L;
public static final String PREFIX = "wx.cp.tp";
private Map<String, WxCpTpSingleProperties> corps = new HashMap<>();
/**
* 配置存储策略,默认内存
*/
private ConfigStorage configStorage = new ConfigStorage();
@Data
@NoArgsConstructor
public static class ConfigStorage implements Serializable {
private static final long serialVersionUID = 4815731027000065434L;
/**
* 存储类型
*/
private StorageType type = StorageType.memory;
/**
* 指定key前缀
*/
private String keyPrefix = "wx:cp:tp";
/**
* redis连接配置
*/
@NestedConfigurationProperty
private WxCpTpMultiRedisProperties redis = new WxCpTpMultiRedisProperties();
/**
* http客户端类型.
*/
private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT;
/**
* http代理主机
*/
private String httpProxyHost;
/**
* http代理端口
*/
private Integer httpProxyPort;
/**
* http代理用户名
*/
private String httpProxyUsername;
/**
* http代理密码
*/
private String httpProxyPassword;
/**
* http 请求最大重试次数
* <pre>
* {@link me.chanjar.weixin.cp.api.WxCpService#setMaxRetryTimes(int)}
* {@link me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl#setMaxRetryTimes(int)}
* </pre>
*/
private int maxRetryTimes = 5;
/**
* http 请求重试间隔
* <pre>
* {@link me.chanjar.weixin.cp.api.WxCpService#setRetrySleepMillis(int)}
* {@link me.chanjar.weixin.cp.api.impl.BaseWxCpServiceImpl#setRetrySleepMillis(int)}
* </pre>
*/
private int retrySleepMillis = 1000;
}
public enum StorageType {
/**
* 内存
*/
memory,
/**
* jedis
*/
jedis,
/**
* redisson
*/
redisson,
/**
* redistemplate
*/
redistemplate
}
public enum HttpClientType {
/**
* HttpClient
*/
HTTP_CLIENT,
/**
* OkHttp
*/
OK_HTTP,
/**
* JoddHttp
*/
JODD_HTTP
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/properties/WxCpTpSingleProperties.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/properties/WxCpTpSingleProperties.java | package com.binarywang.spring.starter.wxjava.cp.properties;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 企业微信企业相关配置属性
*
* @author yl
* created on 2023/10/16
*/
@Data
@NoArgsConstructor
public class WxCpTpSingleProperties implements Serializable {
private static final long serialVersionUID = -7502823825007859418L;
/**
* 微信企业号 corpId
*/
private String corpId;
/**
* 微信企业号 服务商 providerSecret
*/
private String providerSecret;
/**
* 微信企业号应用 token
*/
private String token;
private String encodingAESKey;
/**
* 微信企业号 第三方 应用 ID
*/
private String suiteId;
/**
* 微信企业号应用
*/
private String suiteSecret;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/properties/WxCpTpMultiRedisProperties.java | spring-boot-starters/wx-java-cp-tp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/cp/properties/WxCpTpMultiRedisProperties.java | package com.binarywang.spring.starter.wxjava.cp.properties;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* Redis配置.
*
* @author yl
* created on 2023/10/16
*/
@Data
@NoArgsConstructor
public class WxCpTpMultiRedisProperties implements Serializable {
private static final long serialVersionUID = -5924815351660074401L;
/**
* 主机地址.
*/
private String host;
/**
* 端口号.
*/
private int port = 6379;
/**
* 密码.
*/
private String password;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 数据库.
*/
private int database = 0;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java | spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java | package com.binarywang.spring.starter.wxjava.mp.properties;
import lombok.Data;
import java.io.Serializable;
/**
* redis 配置属性.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2020-08-30
*/
@Data
public class RedisProperties implements Serializable {
private static final long serialVersionUID = -5924815351660074401L;
/**
* 主机地址.
*/
private String host = "127.0.0.1";
/**
* 端口号.
*/
private int port = 6379;
/**
* 密码.
*/
private String password;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 数据库.
*/
private int database = 0;
/**
* sentinel ips
*/
private String sentinelIps;
/**
* sentinel name
*/
private String sentinelName;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/HostConfig.java | spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/HostConfig.java | package com.binarywang.spring.starter.wxjava.mp.properties;
import lombok.Data;
import java.io.Serializable;
@Data
public class HostConfig implements Serializable {
private static final long serialVersionUID = -4172767630740346001L;
/**
* 对应于:https://api.weixin.qq.com
*/
private String apiHost;
/**
* 对应于:https://open.weixin.qq.com
*/
private String openHost;
/**
* 对应于:https://mp.weixin.qq.com
*/
private String mpHost;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java | spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java | package com.binarywang.spring.starter.wxjava.mp.properties;
import com.binarywang.spring.starter.wxjava.mp.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.mp.enums.StorageType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.io.Serializable;
import static com.binarywang.spring.starter.wxjava.mp.enums.StorageType.Memory;
import static com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties.PREFIX;
/**
* 微信接入相关配置属性.
*
* @author someone
*/
@Data
@ConfigurationProperties(PREFIX)
public class WxMpProperties {
public static final String PREFIX = "wx.mp";
/**
* 设置微信公众号的appid.
*/
private String appId;
/**
* 设置微信公众号的app secret.
*/
private String secret;
/**
* 设置微信公众号的token.
*/
private String token;
/**
* 设置微信公众号的EncodingAESKey.
*/
private String aesKey;
/**
* 是否使用稳定版 Access Token
*/
private boolean useStableAccessToken = false;
/**
* 自定义host配置
*/
@NestedConfigurationProperty
private HostConfig hosts;
/**
* 存储策略
*/
private final ConfigStorage configStorage = new ConfigStorage();
@Data
public static class ConfigStorage implements Serializable {
private static final long serialVersionUID = 4815731027000065434L;
/**
* 存储类型.
*/
private StorageType type = Memory;
/**
* 指定key前缀.
*/
private String keyPrefix = "wx";
/**
* redis连接配置.
*/
@NestedConfigurationProperty
private final RedisProperties redis = new RedisProperties();
/**
* http客户端类型.
*/
private HttpClientType httpClientType = HttpClientType.HttpClient;
/**
* http代理主机.
*/
private String httpProxyHost;
/**
* http代理端口.
*/
private Integer httpProxyPort;
/**
* http代理用户名.
*/
private String httpProxyUsername;
/**
* http代理密码.
*/
private String httpProxyPassword;
/**
* 连接超时时间,单位毫秒
*/
private int connectionTimeout = 5000;
/**
* 读数据超时时间,即socketTimeout,单位毫秒
*/
private int soTimeout = 5000;
/**
* 从连接池获取链接的超时时间,单位毫秒
*/
private int connectionRequestTimeout = 5000;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpAutoConfiguration.java | spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.config;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* .
*
* @author someone
*/
@Configuration
@EnableConfigurationProperties(WxMpProperties.class)
@Import({ WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class })
public class WxMpAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpServiceAutoConfiguration.java | spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpServiceAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.config;
import com.binarywang.spring.starter.wxjava.mp.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpComponentsImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceJoddHttpImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 微信公众号相关服务自动注册.
*
* @author someone
*/
@Configuration
public class WxMpServiceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpProperties wxMpProperties) {
HttpClientType httpClientType = wxMpProperties.getConfigStorage().getHttpClientType();
WxMpService wxMpService;
switch (httpClientType) {
case OkHttp:
wxMpService = newWxMpServiceOkHttpImpl();
break;
case JoddHttp:
wxMpService = newWxMpServiceJoddHttpImpl();
break;
case HttpClient:
wxMpService = newWxMpServiceHttpClientImpl();
break;
case HttpComponents:
wxMpService = newWxMpServiceHttpComponentsImpl();
break;
default:
wxMpService = newWxMpServiceImpl();
break;
}
wxMpService.setWxMpConfigStorage(configStorage);
return wxMpService;
}
private WxMpService newWxMpServiceImpl() {
return new WxMpServiceImpl();
}
private WxMpService newWxMpServiceHttpClientImpl() {
return new WxMpServiceHttpClientImpl();
}
private WxMpService newWxMpServiceOkHttpImpl() {
return new WxMpServiceOkHttpImpl();
}
private WxMpService newWxMpServiceJoddHttpImpl() {
return new WxMpServiceJoddHttpImpl();
}
private WxMpService newWxMpServiceHttpComponentsImpl() {
return new WxMpServiceHttpComponentsImpl();
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java | spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.mp.config;
import com.binarywang.spring.starter.wxjava.mp.enums.StorageType;
import com.binarywang.spring.starter.wxjava.mp.properties.RedisProperties;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
import com.google.common.collect.Sets;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.WxMpHostConfig;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;
import redis.clients.jedis.util.Pool;
import java.util.Set;
/**
* 微信公众号存储策略自动配置.
*
* @author Luo
*/
@Slf4j
@Configuration
@RequiredArgsConstructor
public class WxMpStorageAutoConfiguration {
private final ApplicationContext applicationContext;
private final WxMpProperties wxMpProperties;
@Bean
@ConditionalOnMissingBean(WxMpConfigStorage.class)
public WxMpConfigStorage wxMpConfigStorage() {
StorageType type = wxMpProperties.getConfigStorage().getType();
WxMpConfigStorage config;
switch (type) {
case Jedis:
config = jedisConfigStorage();
break;
case RedisTemplate:
config = redisTemplateConfigStorage();
break;
default:
config = defaultConfigStorage();
break;
}
// wx host config
if (null != wxMpProperties.getHosts() && StringUtils.isNotEmpty(wxMpProperties.getHosts().getApiHost())) {
WxMpHostConfig hostConfig = new WxMpHostConfig();
hostConfig.setApiHost(wxMpProperties.getHosts().getApiHost());
hostConfig.setMpHost(wxMpProperties.getHosts().getMpHost());
hostConfig.setOpenHost(wxMpProperties.getHosts().getOpenHost());
config.setHostConfig(hostConfig);
}
return config;
}
private WxMpConfigStorage defaultConfigStorage() {
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
setWxMpInfo(config);
return config;
}
private WxMpConfigStorage jedisConfigStorage() {
Pool<Jedis> jedisPool;
if (wxMpProperties.getConfigStorage() != null && wxMpProperties.getConfigStorage().getRedis() != null
&& StringUtils.isNotEmpty(wxMpProperties.getConfigStorage().getRedis().getHost())) {
jedisPool = getJedisPool();
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
wxMpProperties.getConfigStorage().getKeyPrefix());
setWxMpInfo(wxMpRedisConfig);
return wxMpRedisConfig;
}
private WxMpConfigStorage redisTemplateConfigStorage() {
StringRedisTemplate redisTemplate = null;
try {
redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
try {
if (null == redisTemplate) {
redisTemplate = (StringRedisTemplate) applicationContext.getBean("stringRedisTemplate");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
if (null == redisTemplate) {
redisTemplate = (StringRedisTemplate) applicationContext.getBean("redisTemplate");
}
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
wxMpProperties.getConfigStorage().getKeyPrefix());
setWxMpInfo(wxMpRedisConfig);
return wxMpRedisConfig;
}
private void setWxMpInfo(WxMpDefaultConfigImpl config) {
WxMpProperties properties = wxMpProperties;
WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setAppId(properties.getAppId());
config.setSecret(properties.getSecret());
config.setToken(properties.getToken());
config.setAesKey(properties.getAesKey());
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
// 设置自定义的HttpClient超时配置
ApacheHttpClientBuilder clientBuilder = config.getApacheHttpClientBuilder();
if (clientBuilder == null) {
clientBuilder = DefaultApacheHttpClientBuilder.get();
}
if (clientBuilder instanceof DefaultApacheHttpClientBuilder) {
DefaultApacheHttpClientBuilder defaultBuilder = (DefaultApacheHttpClientBuilder) clientBuilder;
defaultBuilder.setConnectionTimeout(storage.getConnectionTimeout());
defaultBuilder.setSoTimeout(storage.getSoTimeout());
defaultBuilder.setConnectionRequestTimeout(storage.getConnectionRequestTimeout());
config.setApacheHttpClientBuilder(defaultBuilder);
}
config.setUseStableAccessToken(wxMpProperties.isUseStableAccessToken());
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
}
private Pool<Jedis> getJedisPool() {
RedisProperties redis = wxMpProperties.getConfigStorage().getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
if (StringUtils.isNotEmpty(redis.getSentinelIps())) {
Set<String> sentinels = Sets.newHashSet(redis.getSentinelIps().split(","));
return new JedisSentinelPool(redis.getSentinelName(), sentinels);
}
return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
redis.getDatabase());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/HttpClientType.java | spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/HttpClientType.java | package com.binarywang.spring.starter.wxjava.mp.enums;
/**
* httpclient类型.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2020-08-30
*/
public enum HttpClientType {
/**
* HttpClient.
*/
HttpClient,
/**
* OkHttp.
*/
OkHttp,
/**
* JoddHttp.
*/
JoddHttp,
/**
* HttpComponents (Apache HttpClient 5.x).
*/
HttpComponents,
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/StorageType.java | spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/StorageType.java | package com.binarywang.spring.starter.wxjava.mp.enums;
/**
* storage类型.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* created on 2020-08-30
*/
public enum StorageType {
/**
* 内存.
*/
Memory,
/**
* redis(JedisClient).
*/
Jedis,
/**
* redis(Redisson).
*/
Redisson,
/**
* redis(RedisTemplate).
*/
RedisTemplate
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/properties/RedisProperties.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/properties/RedisProperties.java | package com.binarywang.spring.starter.wxjava.channel.properties;
import lombok.Data;
/**
* redis 配置
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Data
public class RedisProperties {
/**
* 主机地址,不填则从spring容器内获取JedisPool
*/
private String host;
/**
* 端口号
*/
private int port = 6379;
/**
* 密码
*/
private String password;
/**
* 超时
*/
private int timeout = 2000;
/**
* 数据库
*/
private int database = 0;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/properties/WxChannelProperties.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/properties/WxChannelProperties.java | package com.binarywang.spring.starter.wxjava.channel.properties;
import com.binarywang.spring.starter.wxjava.channel.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.channel.enums.StorageType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
/**
* 属性配置类
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Data
@ConfigurationProperties(prefix = WxChannelProperties.PREFIX)
public class WxChannelProperties {
public static final String PREFIX = "wx.channel";
/**
* 设置视频号小店的appid
*/
private String appid;
/**
* 设置视频号小店的Secret
*/
private String secret;
/**
* 设置视频号小店消息服务器配置的token.
*/
private String token;
/**
* 设置视频号小店消息服务器配置的EncodingAESKey
*/
private String aesKey;
/**
* 消息格式,XML或者JSON
*/
private String msgDataFormat = "JSON";
/**
* 是否使用稳定版 Access Token
*/
private boolean useStableAccessToken = false;
/**
* 自定义API主机地址,用于替换默认的 https://api.weixin.qq.com
* 例如:http://proxy.company.com:8080
*/
private String apiHostUrl;
/**
* 自定义获取AccessToken地址,用于向自定义统一服务获取AccessToken
* 例如:http://proxy.company.com:8080/oauth/token
*/
private String accessTokenUrl;
/**
* 存储策略
*/
private final ConfigStorage configStorage = new ConfigStorage();
@Data
public static class ConfigStorage {
/**
* 存储类型
*/
private StorageType type = StorageType.Memory;
/**
* 指定key前缀
*/
private String keyPrefix = "wh";
/**
* redis连接配置
*/
@NestedConfigurationProperty
private final RedisProperties redis = new RedisProperties();
/**
* http客户端类型
*/
private HttpClientType httpClientType = HttpClientType.HttpClient;
/**
* http代理主机
*/
private String httpProxyHost;
/**
* http代理端口
*/
private Integer httpProxyPort;
/**
* http代理用户名
*/
private String httpProxyUsername;
/**
* http代理密码
*/
private String httpProxyPassword;
/**
* http 请求重试间隔
* <pre>
* {@link me.chanjar.weixin.channel.api.BaseWxChannelService#setRetrySleepMillis(int)}
* </pre>
*/
private int retrySleepMillis = 1000;
/**
* http 请求最大重试次数
* <pre>
* {@link me.chanjar.weixin.channel.api.BaseWxChannelService#setMaxRetryTimes(int)}
* </pre>
*/
private int maxRetryTimes = 5;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/WxChannelAutoConfiguration.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/WxChannelAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.channel.config;
import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* 自动配置
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@EnableConfigurationProperties(WxChannelProperties.class)
@Import({
WxChannelStorageAutoConfiguration.class,
WxChannelServiceAutoConfiguration.class
})
public class WxChannelAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/WxChannelStorageAutoConfiguration.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/WxChannelStorageAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.channel.config;
import com.binarywang.spring.starter.wxjava.channel.config.storage.WxChannelInJedisConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.channel.config.storage.WxChannelInMemoryConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.channel.config.storage.WxChannelInRedisTemplateConfigStorageConfiguration;
import com.binarywang.spring.starter.wxjava.channel.config.storage.WxChannelInRedissonConfigStorageConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* 微信小程序存储策略自动配置
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@Import({
WxChannelInMemoryConfigStorageConfiguration.class,
WxChannelInJedisConfigStorageConfiguration.class,
WxChannelInRedisTemplateConfigStorageConfiguration.class,
WxChannelInRedissonConfigStorageConfiguration.class
})
public class WxChannelStorageAutoConfiguration {
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/WxChannelServiceAutoConfiguration.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/WxChannelServiceAutoConfiguration.java | package com.binarywang.spring.starter.wxjava.channel.config;
import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.channel.api.WxChannelService;
import me.chanjar.weixin.channel.api.impl.WxChannelServiceImpl;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 微信小程序平台相关服务自动注册
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@AllArgsConstructor
public class WxChannelServiceAutoConfiguration {
private final WxChannelProperties properties;
/**
* Channel Service
*
* @return Channel Service
*/
@Bean
@ConditionalOnMissingBean(WxChannelService.class)
@ConditionalOnBean(WxChannelConfig.class)
public WxChannelService wxChannelService(WxChannelConfig wxChannelConfig) {
WxChannelService wxChannelService = new WxChannelServiceImpl();
wxChannelService.setConfig(wxChannelConfig);
return wxChannelService;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/AbstractWxChannelConfigStorageConfiguration.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/AbstractWxChannelConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.channel.config.storage;
import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import me.chanjar.weixin.channel.config.impl.WxChannelDefaultConfigImpl;
import org.apache.commons.lang3.StringUtils;
/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
public abstract class AbstractWxChannelConfigStorageConfiguration {
protected WxChannelDefaultConfigImpl config(WxChannelDefaultConfigImpl config, WxChannelProperties properties) {
config.setAppid(StringUtils.trimToNull(properties.getAppid()));
config.setSecret(StringUtils.trimToNull(properties.getSecret()));
config.setToken(StringUtils.trimToNull(properties.getToken()));
config.setAesKey(StringUtils.trimToNull(properties.getAesKey()));
config.setMsgDataFormat(StringUtils.trimToNull(properties.getMsgDataFormat()));
config.setStableAccessToken(properties.isUseStableAccessToken());
config.setApiHostUrl(StringUtils.trimToNull(properties.getApiHostUrl()));
config.setAccessTokenUrl(StringUtils.trimToNull(properties.getAccessTokenUrl()));
WxChannelProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
int maxRetryTimes = configStorageProperties.getMaxRetryTimes();
if (configStorageProperties.getMaxRetryTimes() < 0) {
maxRetryTimes = 0;
}
int retrySleepMillis = configStorageProperties.getRetrySleepMillis();
if (retrySleepMillis < 0) {
retrySleepMillis = 1000;
}
config.setRetrySleepMillis(retrySleepMillis);
config.setMaxRetryTimes(maxRetryTimes);
return config;
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/WxChannelInMemoryConfigStorageConfiguration.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/WxChannelInMemoryConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.channel.config.storage;
import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import me.chanjar.weixin.channel.config.impl.WxChannelDefaultConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@ConditionalOnProperty(prefix = WxChannelProperties.PREFIX + ".config-storage", name = "type",
matchIfMissing = true, havingValue = "memory")
@RequiredArgsConstructor
public class WxChannelInMemoryConfigStorageConfiguration extends AbstractWxChannelConfigStorageConfiguration {
private final WxChannelProperties properties;
@Bean
@ConditionalOnMissingBean(WxChannelProperties.class)
public WxChannelConfig wxChannelConfig() {
WxChannelDefaultConfigImpl config = new WxChannelDefaultConfigImpl();
return this.config(config, properties);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/WxChannelInRedisTemplateConfigStorageConfiguration.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/WxChannelInRedisTemplateConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.channel.config.storage;
import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import me.chanjar.weixin.channel.config.impl.WxChannelRedisConfigImpl;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@ConditionalOnProperty(prefix = WxChannelProperties.PREFIX + ".config-storage", name = "type", havingValue = "redistemplate")
@ConditionalOnClass(StringRedisTemplate.class)
@RequiredArgsConstructor
public class WxChannelInRedisTemplateConfigStorageConfiguration extends AbstractWxChannelConfigStorageConfiguration {
private final WxChannelProperties properties;
private final ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean(WxChannelConfig.class)
public WxChannelConfig wxChannelConfig() {
WxChannelRedisConfigImpl config = getWxChannelInRedisTemplateConfig();
return this.config(config, properties);
}
private WxChannelRedisConfigImpl getWxChannelInRedisTemplateConfig() {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
return new WxChannelRedisConfigImpl(redisOps, properties.getConfigStorage().getKeyPrefix());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/WxChannelInJedisConfigStorageConfiguration.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/WxChannelInJedisConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.channel.config.storage;
import com.binarywang.spring.starter.wxjava.channel.properties.RedisProperties;
import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import me.chanjar.weixin.channel.config.impl.WxChannelRedisConfigImpl;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@ConditionalOnProperty(prefix = WxChannelProperties.PREFIX + ".config-storage", name = "type", havingValue = "jedis")
@ConditionalOnClass({JedisPool.class, JedisPoolConfig.class})
@RequiredArgsConstructor
public class WxChannelInJedisConfigStorageConfiguration extends AbstractWxChannelConfigStorageConfiguration {
private final WxChannelProperties properties;
private final ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean(WxChannelConfig.class)
public WxChannelConfig wxChannelConfig() {
WxChannelRedisConfigImpl config = getWxChannelRedisConfig();
return this.config(config, properties);
}
private WxChannelRedisConfigImpl getWxChannelRedisConfig() {
RedisProperties redisProperties = properties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
jedisPool = getJedisPool();
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
return new WxChannelRedisConfigImpl(redisOps, properties.getConfigStorage().getKeyPrefix());
}
private JedisPool getJedisPool() {
WxChannelProperties.ConfigStorage storage = properties.getConfigStorage();
RedisProperties redis = storage.getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
config.setMaxTotal(redis.getMaxActive());
}
if (redis.getMaxIdle() != null) {
config.setMaxIdle(redis.getMaxIdle());
}
if (redis.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redis.getMaxWaitMillis());
}
if (redis.getMinIdle() != null) {
config.setMinIdle(redis.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), redis.getDatabase());
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/WxChannelInRedissonConfigStorageConfiguration.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/config/storage/WxChannelInRedissonConfigStorageConfiguration.java | package com.binarywang.spring.starter.wxjava.channel.config.storage;
import com.binarywang.spring.starter.wxjava.channel.properties.RedisProperties;
import com.binarywang.spring.starter.wxjava.channel.properties.WxChannelProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.channel.config.WxChannelConfig;
import me.chanjar.weixin.channel.config.impl.WxChannelRedissonConfigImpl;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Configuration
@ConditionalOnProperty(prefix = WxChannelProperties.PREFIX + ".config-storage", name = "type", havingValue = "redisson")
@ConditionalOnClass({Redisson.class, RedissonClient.class})
@RequiredArgsConstructor
public class WxChannelInRedissonConfigStorageConfiguration extends AbstractWxChannelConfigStorageConfiguration {
private final WxChannelProperties properties;
private final ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean(WxChannelConfig.class)
public WxChannelConfig wxChannelConfig() {
WxChannelRedissonConfigImpl config = getWxChannelRedissonConfig();
return this.config(config, properties);
}
private WxChannelRedissonConfigImpl getWxChannelRedissonConfig() {
RedisProperties redisProperties = properties.getConfigStorage().getRedis();
RedissonClient redissonClient;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
redissonClient = getRedissonClient();
} else {
redissonClient = applicationContext.getBean(RedissonClient.class);
}
return new WxChannelRedissonConfigImpl(redissonClient, properties.getConfigStorage().getKeyPrefix());
}
private RedissonClient getRedissonClient() {
WxChannelProperties.ConfigStorage storage = properties.getConfigStorage();
RedisProperties redis = storage.getRedis();
Config config = new Config();
config.useSingleServer()
.setAddress("redis://" + redis.getHost() + ":" + redis.getPort())
.setDatabase(redis.getDatabase())
.setPassword(redis.getPassword());
config.setTransportMode(TransportMode.NIO);
return Redisson.create(config);
}
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
binarywang/WxJava | https://github.com/binarywang/WxJava/blob/84b5c4d2d0774f800237634e5d0336f53c004fe3/spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/enums/HttpClientType.java | spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/enums/HttpClientType.java | package com.binarywang.spring.starter.wxjava.channel.enums;
/**
* httpclient类型
*
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
public enum HttpClientType {
/**
* HttpClient
*/
HttpClient
}
| java | Apache-2.0 | 84b5c4d2d0774f800237634e5d0336f53c004fe3 | 2026-01-04T14:46:39.499027Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.