[测评系统]--测评系统核心代码库
linzhijie
2021-03-11 84fea994d2db7dc313ad1774f34eb12a45f8d6e7
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
package com.ots.project.tool.sms;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
 
@Slf4j
@Component
public class ShortMessageImpl implements ShortMessage {
    @Autowired
    ZjunShortMessageImpl zjunShortMessage;
    @Override
    public Returnsms sendSms(List<String> mobiles, String sign, String message) {
        Returnsms returnsms = null;
        try {
            String telnoStrs = getMobilesStr(mobiles);
            return zjunShortMessage.sendmsg(telnoStrs, sign, message);
        } catch (Exception e) {
            log.error("【发送{}短信失败:】", mobiles, e);
            returnsms.setReturnstatus(ZjunShortMessageImpl.RET_STATUS_FAIL);
            returnsms.setMessage(e.getMessage());
        }
        return returnsms;
    }
    @Override
    public List<Statusbox> getReport() {
        return zjunShortMessage.getReport();
    }
    @Override
    public ResponseSms sendInternationalSms(List<String> mobiles, String message) {
        ResponseSms responseSms = new ResponseSms();
        try {
            String substring = getMobilesStr(mobiles);
            String retStr = InternationalMessage.SendPost(InternationalMessage.INTERNATIONAL_SMS_URL, InternationalMessage.INTERNATIONAL_SMS_COMMAND, "gpcz68", "vlcfXHa4", substring, message, null);
            Map mapValue = new HashMap();
            Stream.of(retStr.split("&")).forEach(p -> {
                String[] split = p.split("=");
                mapValue.put(split[0], split[1]);
            });
            responseSms = BeanUtil.mapToBeanIgnoreCase(mapValue, ResponseSms.class, true);
        } catch (Exception e) {
            e.printStackTrace();
            responseSms.setMtstat(ResponseSms.Mterrcode.RET_502.getCode() + " 程序异常:" + e.getMessage());
        }
        return responseSms;
    }
    private String getMobilesStr(List<String> mobiles) {
        StringBuilder builder = new StringBuilder();
        mobiles.stream().forEach(it -> builder.append(it + ","));
        return builder.substring(0, builder.length() - 1);
    }
    public static void main(String[] args) {
        ShortMessageImpl impl = new ShortMessageImpl();
        String mobilesStr = impl.getMobilesStr(Arrays.asList("13512745445", "13512745445", "13512745445", "13512745445"));
        System.out.println(mobilesStr);
        String str = "command=MT_RESPONSE&cpid=gpcz68&cppwd=000&mtmsgid=059acdf58165ba&mtstat=ACCEPTD&mterrcode=000";
        Map mapValue = new HashMap();
        Stream.of(str.split("&")).forEach(p -> {
            String[] split = p.split("=");
            mapValue.put(split[0], split[1]);
        });
        ResponseSms responseSms = BeanUtil.mapToBeanIgnoreCase(mapValue, ResponseSms.class, true);
        System.out.println(JSON.toJSON(responseSms));
    }
}