--POST发送短信接口演示,add by: liang   2019-11-09
function httpPost()
    local sOut = CTNString();
    --POST的参数就是一个字符串,使用&符号隔开,跟get参数格式一样
    local sParam = 'apikey=08b0bfd1ef078f9be6b40333aab745dd&mobile=#photo#&text=【塔网科技】MES通知,发生时间:#time#,描述:#info#';
    sParam = string.gsub(sParam, '#photo#', '15658877663,13071817122');
    sParam = string.gsub(sParam, '#time#', cutil:getSys14Time());
    sParam = string.gsub(sParam, '#info#', '短信测试');
    local sU = cutil:a2u(sParam);--脚本是GB2312,接口一般都是UTF8
    cutil:httpPost('http://sms.yunpian.com/v2/sms/batch_send.json', sOut, sU);
    local sRet = sOut:get();
    if #sRet <= 0 then
        return print('返回值为空');
    end
    sRet = cutil:u2a(sRet);--html一般用的UTF8
    --{"total_count":2,"total_fee":"0.1000","unit":"RMB","data":[{"code":0,"count":1,"fee":0.05,"mobile":"15658877663","msg":"发送成功","sid":47949346166,"unit":"RMB"},{"code":0,"count":1,"fee":0.05,"mobile":"13071817122","msg":"发送成功","sid":47949346168,"unit":"RMB"}]}
    print( sRet )
    if _G['_load_tn_json2lua'] == nil then
        --serv:use(luaid(), 'tn_json2lua');--服务端脚本引用
        ui:use('tn_json2lua');--客户端脚本引用
        _G['_load_tn_json2lua'] = true;
    end
    local res = json_decode(sRet);--JSON字符串转成LUA的table对象
    if res == nil then
        return;
    end
    if res.unit ~= nil then--使用table中的变量的时候,一定要先判断nil,防止变量不存在
        print( res.unit )
    end
    if res.data ~= nil then
        for i=1,#res.data do
            print( res.data[i].mobile..'->'..res.data[i].msg )
        end
    end
end
Copyright © TouchNet 2015 all right reserved,powered by Gitbook最后修订时间: 2022-06-21 09:21:04

results matching ""

    No results matching ""