hls_interface_sms.lsc 2.97 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
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
<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:s="leaf.plugin.script" xmlns:a="http://www.leaf-framework.org/application" xmlns:p="uncertain.proc" trace="true">
    <a:init-procedure>
        <s:server-script><![CDATA[
            importPackage(Packages.deron_sms_interface);
            
            //step1 配置信息
            var sms_server_bm = $bm('sys.SYS403.sys_sms_server');
            var sms_server_result = sms_server_bm.queryAsMap({});
            var sms_server_records = sms_server_result.getChildren();
            var server_url = sms_server_records[0].server_url;
            var CorpID = sms_server_records[0].serviceid;
            var Pwd = sms_server_records[0].password;
            //step2 发送短信
            
            function sendsms() {
                // 查询待发送短信表
                var sms_id = $ctx.parameter.sms_id;
                var sms_list_bm = $bm('sys.SYS401.sys_sms_list');
            
                if (sms_id) {
                    var sms_list_result = sms_list_bm.queryAsMap({
                        "sms_id": sms_id
                    });
                    var sms_list_records = sms_list_result.getChildren();
                } else {
                    var sms_list_result = sms_list_bm.queryAsMap({});
                    var sms_list_records = sms_list_result.getChildren();
                }
                for (var i = 0;i < sms_list_records.length;i++) {
                    var Phones = sms_list_records[i].phone_number;
                    var content = sms_list_records[i].text;
                    var sms_id = sms_list_records[i].sms_id;
                    try {
                         // var sms = new Packages.org.pqsoft.sms.SendSms();
                        // var result = new String(SendSms.doSend(server_url, CorpID, Pwd, content, Phones), "UTF-8");
                        // var result = send(server_url, CorpID, Pwd, content, Phones);
                        // println("发送短信");
                        var sms = new SendSms();
                        var result = sms.doSend(server_url, CorpID, Pwd, content, Phones);
                        var req_response = result.toString();
                        // req_response = parseInt(req_response);
                        var json_result = {
                            "sendflag": result
                        };
                        $ctx.parameter.json = JSON.stringify(json_result);
                        println("result:" + $ctx.parameter.json);
                    } catch (e) {
                        println("抛出异常:" + e);
                    }
            
                    // 发送短信后,逻辑处理
                    $bm('nt.sys_sms_list').update({
                        sms_id: sms_id,
                        req_response: req_response
                    });
                }
            }
            sendsms();
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter"/>
</a:service>