Merge pull request #17 from jwqsocool/shb

新增支付宝小程序消息推送功能
pull/20/head
Java3y 2 years ago committed by GitHub
commit 542421aa1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -78,6 +78,12 @@ public class SendAccountConstant {
public static final String WECHAT_MINI_PROGRAM_ACCOUNT_KEY = "miniProgramAccount";
public static final String WECHAT_MINI_PROGRAM_PREFIX = "mini_program_";
/**
*
*/
public static final String ALIPAY_MINI_PROGRAM_ACCOUNT_KEY = "alipayMiniProgramAccount";
public static final String ALIPAY_MINI_PROGRAM_PREFIX = "alipay_mini_program_";
/**
*
*/

@ -0,0 +1,42 @@
package com.java3y.austin.common.dto.account;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author jwq
*
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AlipayMiniProgramAccount {
/**
*
*/
private String privateKey;
/**
*
*/
private String alipayPublicKey;
/**
* AppID
*/
private String appId;
/**
* Id
*/
private String userTemplateId;
/**
*
*/
private String page;
}

@ -0,0 +1,25 @@
package com.java3y.austin.common.dto.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
/**
* @author jwq
*
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AlipayMiniProgramContentModel extends ContentModel{
/**
*
*/
Map<String, String> map;
}

@ -28,6 +28,7 @@ public enum ChannelType {
DING_DING_WORK_NOTICE(90, "dingDingWorkNotice(钉钉工作通知)", DingDingWorkContentModel.class, "ding_ding_work_notice"),
ENTERPRISE_WE_CHAT_ROBOT(100, "enterpriseWeChat(企业微信机器人)", EnterpriseWeChatRobotContentModel.class, "enterprise_we_chat_robot"),
FEI_SHU_ROBOT(110, "feiShuRoot(飞书机器人)", FeiShuRobotContentModel.class, "fei_shu_robot"),
ALIPAY_MINI_PROGRAM(120,"alipayMiniProgram(支付宝小程序)",AlipayMiniProgramContentModel.class,"alipay_mini_program"),
;
/**

@ -57,6 +57,11 @@
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-cp</artifactId>
</dependency>
<!--支付宝SDK-->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,18 @@
package com.java3y.austin.handler.alipay;
import com.alipay.api.AlipayApiException;
import com.java3y.austin.handler.domain.alipay.AlipayMiniProgramParam;
/**
* @author jwq
*
*/
public interface AlipayMiniProgramAccountService {
/**
*
*
* @param miniProgramParam
* @throws AlipayApiException alipay
*/
void send(AlipayMiniProgramParam miniProgramParam) throws AlipayApiException;
}

@ -0,0 +1,89 @@
package com.java3y.austin.handler.alipay.impl;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayOpenAppMiniTemplatemessageSendModel;
import com.alipay.api.request.AlipayOpenAppMiniTemplatemessageSendRequest;
import com.java3y.austin.common.constant.SendAccountConstant;
import com.java3y.austin.common.dto.account.AlipayMiniProgramAccount;
import com.java3y.austin.handler.alipay.AlipayMiniProgramAccountService;
import com.java3y.austin.handler.domain.alipay.AlipayMiniProgramParam;
import com.java3y.austin.support.utils.AccountUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* @author jwq
*
*/
@Service
@Slf4j
public class AlipayMiniProgramAccountServiceImpl implements AlipayMiniProgramAccountService {
@Autowired
private AccountUtils accountUtils;
/**
*
*
* @param miniProgramParam
* @throws AlipayApiException alipay
*/
@Override
public void send(AlipayMiniProgramParam miniProgramParam) throws AlipayApiException {
AlipayMiniProgramAccount miniProgramAccount = accountUtils.getAccount(miniProgramParam.getSendAccount(),
SendAccountConstant.ALIPAY_MINI_PROGRAM_ACCOUNT_KEY,
SendAccountConstant.ALIPAY_MINI_PROGRAM_PREFIX,
AlipayMiniProgramAccount.class);
AlipayClient client = initService(miniProgramAccount);
List<AlipayOpenAppMiniTemplatemessageSendRequest> request = assembleReq(miniProgramParam, miniProgramAccount);
for(AlipayOpenAppMiniTemplatemessageSendRequest req : request){
client.execute(req);
}
}
/**
*
*/
private List<AlipayOpenAppMiniTemplatemessageSendRequest> assembleReq(AlipayMiniProgramParam alipayMiniProgramParam, AlipayMiniProgramAccount alipayMiniProgramAccount){
Set<String> receiver = alipayMiniProgramParam.getToUserId();
List<AlipayOpenAppMiniTemplatemessageSendRequest> requestList = new ArrayList<>(receiver.size());
for(String toUserId : receiver){
AlipayOpenAppMiniTemplatemessageSendRequest request = new AlipayOpenAppMiniTemplatemessageSendRequest();
AlipayOpenAppMiniTemplatemessageSendModel model = new AlipayOpenAppMiniTemplatemessageSendModel();
model.setToUserId(toUserId);
model.setUserTemplateId(alipayMiniProgramAccount.getUserTemplateId());
model.setPage(alipayMiniProgramAccount.getPage());
model.setData(alipayMiniProgramParam.getData().toString());
request.setBizModel(model);
requestList.add(request);
}
return requestList;
}
/**
*
*/
private AlipayClient initService(AlipayMiniProgramAccount alipayMiniProgramAccount) throws AlipayApiException {
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipaydev.com/gateway.do");
alipayConfig.setAppId(alipayMiniProgramAccount.getAppId());
alipayConfig.setPrivateKey(alipayMiniProgramAccount.getPrivateKey());
alipayConfig.setFormat("json");
alipayConfig.setAlipayPublicKey(alipayMiniProgramAccount.getAlipayPublicKey());
alipayConfig.setCharset("utf-8");
alipayConfig.setSignType("RSA2");
return new DefaultAlipayClient(alipayConfig);
}
}

@ -0,0 +1,43 @@
package com.java3y.austin.handler.domain.alipay;
import lombok.Builder;
import lombok.Data;
import java.util.Map;
import java.util.Set;
/**
* @author jwq
*
*/
@Data
@Builder
public class AlipayMiniProgramParam {
/**
* Id
*/
private Long messageTemplateId;
/**
*
*/
private Integer sendAccount;
/**
* UserId
*/
private Set<String> toUserId;
/**
* { "key1": { "value": any }, "key2": { "value": any } }
*/
private Map<String, String> data;
// /**
// * 支付消息模板:需传入用户发生的交易行为的支付宝交易号 trade_no
// * 表单提交模板:需传入用户在小程序触发表单提交事件获得的表单号;
// * 刷脸消息模板需传入在IOT刷脸后得到的ftoken等用于信息发送的校验。
// * 说明:订阅消息模板无需传入本参数。
// */
// private String formId;
}

@ -0,0 +1,67 @@
package com.java3y.austin.handler.handler.impl;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables;
import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.dto.model.AlipayMiniProgramContentModel;
import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.alipay.AlipayMiniProgramAccountService;
import com.java3y.austin.handler.domain.alipay.AlipayMiniProgramParam;
import com.java3y.austin.handler.handler.BaseHandler;
import com.java3y.austin.handler.handler.Handler;
import com.java3y.austin.support.domain.MessageTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author jwq
*
*/
@Component
@Slf4j
public class AlipayMiniProgramAccountHandler extends BaseHandler implements Handler {
@Autowired
private AlipayMiniProgramAccountService alipayMiniProgramAccountService;
public AlipayMiniProgramAccountHandler() {
channelCode = ChannelType.ALIPAY_MINI_PROGRAM.getCode();
}
@Override
public boolean handler(TaskInfo taskInfo) {
AlipayMiniProgramParam miniProgramParam = buildMiniProgramParam(taskInfo);
try {
alipayMiniProgramAccountService.send(miniProgramParam);
}catch (Exception e) {
log.error("AlipayMiniProgramAccountHandler#handler fail:{},params:{}",
Throwables.getStackTraceAsString(e), JSON.toJSONString(taskInfo));
return false;
}
return true;
}
/**
* taskInfo
*
* @param taskInfo
* @return AlipayMiniProgramParam
*/
private AlipayMiniProgramParam buildMiniProgramParam(TaskInfo taskInfo){
AlipayMiniProgramParam param = AlipayMiniProgramParam.builder()
.toUserId(taskInfo.getReceiver())
.messageTemplateId(taskInfo.getMessageTemplateId())
.sendAccount(taskInfo.getSendAccount())
.build();
AlipayMiniProgramContentModel contentModel = (AlipayMiniProgramContentModel) taskInfo.getContentModel();
param.setData(contentModel.getMap());
return param;
}
@Override
public void recall(MessageTemplate messageTemplate) {
}
}

@ -22,6 +22,7 @@ public class AccountUtils {
private ConfigService config;
/**
* local.properties
* (key:smsAccount)[{"sms_10":{"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"AKIDhDxxxxxxxx1WljQq","secretKey":"B4hwww39yxxxrrrrgxyi","smsSdkAppId":"1423123125","templateId":"1182097","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云"}},{"sms_20":{"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json","apikey":"caffff8234234231b5cd7","tpl_id":"523333332","supplierId":20,"supplierName":"云片"}}]
* (key:emailAccount)[{"email_10":{"host":"smtp.qq.com","port":465,"user":"23423423@qq.com","pass":"23423432432423423","from":"234@qq.com","starttlsEnable":true,"auth":true,"sslEnable":true}},{"email_20":{"host":"smtp.163.com","port":465,"user":"22222@163.com","pass":"23432423","from":"234324324234@163.com","starttlsEnable":false,"auth":true,"sslEnable":true}}]
* (key:enterpriseWechatAccount)[{"enterprise_wechat_10":{"corpId":"wwf87603333e00069c","corpSecret":"-IFWxS2222QxzPIorNV11144D915DM","agentId":10044442,"token":"rXROB3333Kf6i","aesKey":"MKZtoFxHIM44444M7ieag3r9ZPUsl"}}]
@ -29,6 +30,7 @@ public class AccountUtils {
* (key:dingDingWorkNoticeAccount) [{"ding_ding_work_notice_10":{"appKey":"dingh6yyyyyyycrlbx","appSecret":"tQpvmkR863333yyyyyHP3QHyyyymy9Ao1yoL1oQX5NsdfsWHvWKbTu","agentId":"1523123123183622"}}]
* (key:officialAccount) [{"official_10":{"appId":"wxecb4693d2eef1ea7","secret":"624asdfsa1640d769ba20120821","templateId":"JHUk6eE9T5Ts7asdfsadfiKNDQsk-Q","url":"http://weixin.qq.com/download","miniProgramId":"xiaochengxuappid12345","path":"index?foo=bar"}}]
* (key:miniProgramAccount) [{"mini_program_10":{"appId":"wxecb4693d2eef1ea7","appSecret":"6240870f4d91701640d769ba20120821","templateId":"JHUk6eE9T5TasdfCrQsk-Q","grantType":"client_credential","miniProgramState":"trial","page":"index?foo=bar"}}]
* (key:alipayMiniProgramAccount) [{"alipay_mini_program_10":{"privateKey":"MIIEvQIBADANB......","alipayPublicKey":"MIIBIjANBg...","appId":"2014********7148","userTemplateId":"MDI4YzIxMDE2M2I5YTQzYjUxNWE4MjA4NmU1MTIyYmM=","page":"page/component/index"}}]
*/
public <T> T getAccount(Integer sendAccount, String apolloKey, String prefix, Class<T> clazz) {
String accountValues = config.getProperty(apolloKey, AustinConstant.APOLLO_DEFAULT_VALUE_JSON_ARRAY);

@ -196,6 +196,13 @@
<version>${weixin-java}</version>
</dependency>
<!-- 支付宝sdk https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java -->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.33.39.ALL</version>
</dependency>
<!--阿里云 钉钉 SDK-->
<dependency>
<groupId>com.aliyun</groupId>

Loading…
Cancel
Save