java110
2023-08-21 cb921ad901790925db64afc1bcbafb678e8a12b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.java110.job.msgNotify.ali;
 
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.java110.core.factory.AliSendMessageFactory;
import com.java110.core.factory.CommunitySettingFactory;
import com.java110.core.factory.LogFactory;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.owner.OwnerDto;
import com.java110.intf.user.IOwnerV1InnerServiceSMO;
import com.java110.intf.user.IUserV1InnerServiceSMO;
import com.java110.job.msgNotify.IMsgNotify;
import com.java110.utils.cache.MappingCache;
import com.java110.utils.util.Assert;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service("aliMsgNotifyImpl")
public class AliMsgNotifyImpl implements IMsgNotify {
    private final static Logger logger = LoggerFactory.getLogger(AliMsgNotifyImpl.class);
    @Autowired
    private IOwnerV1InnerServiceSMO ownerV1InnerServiceSMOImpl;
 
    @Override
    public ResultVo sendApplyReturnFeeMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
 
 
    /**
     * 发送欠费 账单信息
     *
     * 需要在阿里云 申请短信模板为
     * 尊敬的业主,您${house}的${feeType},账单日期${date}至${date2},缴费金额:${mount}元,请及时缴费
     *
     * @param communityId 小区
     * @param userId      用户
     * @param content     {
     *                    "feeTypeName",
     *                    "payerObjName",
     *                    "billAmountOwed",
     *                    "date",
     *                    url
     *                    }
     * @return
     */
    @Override
    public ResultVo sendOweFeeMsg(String communityId, String userId, String ownerId, JSONObject content) {
 
 
        if (StringUtil.isEmpty(ownerId) || ownerId.startsWith("-")) {
            throw new IllegalArgumentException("业主不存在,ownerId = " + ownerId);
        }
 
 
        OwnerDto ownerDto = new OwnerDto();
        ownerDto.setMemberId(ownerId);
        ownerDto.setCommunityId(communityId);
        List<OwnerDto> ownerDtos = ownerV1InnerServiceSMOImpl.queryOwners(ownerDto);
 
        Assert.listOnlyOne(ownerDtos, "业主不存在,ownerId = " + ownerId);
 
        String accessKeyId = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_KEY_ID");
        String accessSecret = CommunitySettingFactory.getValue(communityId, "ALI_ACCESS_SECRET");
        String region = CommunitySettingFactory.getValue(communityId, "ALI_REGION");
        String signName = CommunitySettingFactory.getValue(communityId, "ALI_SIGN_NAME");
        String templateCode = CommunitySettingFactory.getValue(communityId, "ALI_OWE_TEMPLATE_CODE");
        DefaultProfile profile = DefaultProfile.getProfile(region,
                accessKeyId,
                accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
 
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", region);
        request.putQueryParameter("PhoneNumbers", ownerDtos.get(0).getLink());
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
 
        JSONObject param = new JSONObject();
        param.put("house", content.getString("payerObjName"));
        param.put("feeType", content.getString("feeTypeName"));
        param.put("date", content.getString("date").split("~")[0]);
        param.put("date2", content.getString("date").split("~")[1]);
        param.put("mount", content.getString("billAmountOwed"));
        request.putQueryParameter("TemplateParam", param.toString());
 
        try {
            CommonResponse response = client.getCommonResponse(request);
            logger.debug("发送验证码信息:{}", response.getData());
            LogFactory.saveOutLog("SMS", param.toString(), new ResponseEntity(response.getData(), HttpStatus.OK));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return null;
    }
 
    @Override
    public ResultVo sendPayFeeMsg(String communityId, String userId, JSONObject content, String role) {
        return null;
    }
 
    @Override
    public ResultVo sendAddOwnerRepairMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
 
    @Override
    public ResultVo sendDistributeRepairStaffMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
 
    @Override
    public ResultVo sendDistributeRepairOwnerMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
 
    @Override
    public ResultVo sendFinishRepairOwnerMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
 
    @Override
    public ResultVo sendReturnRepairMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
 
    @Override
    public ResultVo sendOaDistributeMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
 
    @Override
    public ResultVo sendOaCreateStaffMsg(String communityId, String userId, JSONObject content) {
        return null;
    }
}