Salesforce 发送短信信息
来源:互联网 发布:中国象棋哪个软件最好 编辑:程序博客网 时间:2024/05/17 05:19
public class SMS {
private String url;
private String url1;
private String url2;
private String result;
public SMS(){ url=''; url1=''; url2=''; result=''; }//发送一条短信,接收一个电话号码和短信内容,返回一个请求结果状态public String sendSMS (String content,String phone,String exId) { url2 = '&ac='+Label.SMSAccount +'&authkey='+ Label.SMSPassWord +'&cgid=16&c=' + EncodingUtil.urlEncode(content, 'utf8') +'&m='+phone; url1 = 'http://192.168.0.20:8012/OpenPlatform/OpenApi?action=sendOnce'; //构造短信接口url格式 url = url1 + url2; system.debug('url'+url); //发送http请求,需要在远程站点设置用设置访问的网址url,否则请求会失败 HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('GET'); req.setTimeout(12000); Http http = new Http(); HttpResponse res = http.send(req); System.debug(res.getStatus()+'==============sms result========' +'|'+res.getStatusCode()); System.debug('==============sms result2========' +'|'+res.getBody()); //测试短信接口返回的状态,100表示已经发送(请求的格式正确,成功连接到短信接口),但是并不代表短信发送到对方手机上 //当手机号码为连续的任何数字都会成功并返回100状态 XmlStreamReader xsr = new XmlStreamReader(res.getBody()); SMSInfo__c info =[SELECT id,Status__c,msgId__c FROM SMSInfo__c WHERE TimeNum__c=:exId limit 1]; xsr.next(); while(xsr.hasNext()){ if(xsr.isStartElement()){ system.debug('name:'+xsr.getLocalName()); if(xsr.getLocalName()=='xml'){ for(integer i=0;i<xsr.getAttributeCount();i++){ if(xsr.getAttributeLocalName(i)=='result'){ info.Status__c = xsr.getAttributeValueAt(i); } } }else if(xsr.getLocalName()=='Item'){ for(integer i=0;i<xsr.getAttributeCount();i++){ if(xsr.getAttributeLocalName(i)=='msgid'){ info.msgId__c = xsr.getAttributeValueAt(i); } } } } xsr.next(); } update info; return res.getStatus();}public static void doFutureSend(String phone,String content){ SMSInfo__c info = new SMSInfo__c(); info.phone__c = phone; info.content__c = content; info.Status__c = '2';//未发送 info.TimeNum__c = String.valueOf(DateTime.now().getTime()); insert info; sendMethod(phone,content,info.TimeNum__c);}//出差申请与拜访记录插入 微信 数据public static void doInsert(String content, List<User> leaders, String type){ List<SMSInfo__c> smsList = new List<SMSInfo__c>(); DateTime now = System.now(); Datetime lastDateTime = now.addDays(-2); List<SMSInfo__c> infoList = [SELECT Id, content__c, phone__c FROM SMSInfo__c where (addDate__c>: lastDateTime and addDate__c<:now) and type__c =: type ]; Map<String, SMSInfo__c> infoMap = new Map<String, SMSInfo__c>(); for(SMSInfo__c info : infoList){ infoMap.put(info.content__c, info); } Integer i = 0; if(!infoMap.containsKey(content)){ for(User leader : leaders){ SMSInfo__c info = new SMSInfo__c(); info.weChatAgentId__c= Label.weChatAgentId; info.weChatNumber__c= leader.weChatNumber__c; info.phone__c = leader.phone; info.content__c = content; info.Status__c = '2';//未发送 info.type__c = type; info.addDate__c = now; info.TimeNum__c = String.valueOf(DateTime.now().getTime() + i++); smsList.add(info); } } insert smsList; }//出差申请与拜访记录插入 短信 数据public static void doInsert2(String content, List<User> leaders, String type){ List<SMSInfo__c> smsList = new List<SMSInfo__c>(); DateTime now = System.now(); Datetime lastDateTime = now.addDays(-2); List<SMSInfo__c> infoList = [SELECT Id, content__c, phone__c FROM SMSInfo__c where (addDate__c>: lastDateTime and addDate__c<:now) and type__c =: type ]; Map<String, SMSInfo__c> infoMap = new Map<String, SMSInfo__c>(); for(SMSInfo__c info : infoList){ infoMap.put(info.content__c, info); } Integer i = 0; if(!infoMap.containsKey(content)){ for(User leader : leaders){ SMSInfo__c info = new SMSInfo__c(); info.phone__c = leader.phone; info.content__c = content; info.Status__c = '2';//未发送 info.type__c = type; info.addDate__c = now; info.TimeNum__c = String.valueOf(DateTime.now().getTime() + i++); smsList.add(info); } } insert smsList; }@future(callout=true)public static void sendMethod(String phoneNum,String content,String exId){ SMS s= new SMS(); String status =''; status = s.sendSMS(content, phoneNum, exId); } //验证电话号码是否正确 public boolean isPhoneNumber(String str) { boolean flag = false; Pattern p = Pattern.compile('^[1][3,4,5,8][0-9]{9}$'); // 验证手机号 Matcher m = p.matcher(str); return m.matches(); }
}
0 0
- Salesforce 发送短信信息
- Salesforce 发送公共信息
- Android发送短信信息
- Salesforce 发送业务员未提交任务短信提醒经理
- android发送短信和拦截短信信息
- android短信后台发送信息判断
- Salesforce 发送微信
- Salesforce -- Apex发送电子邮件
- 使用MTM发送中文短信 需要更改的配置信息
- android4.0.4源码修改监控短信发送信息
- Android SmsManager(短信管理器),发送短信息
- 发送短信
- 发送短信
- 发送短信
- 短信发送
- 发送短信
- 发送短信
- 短信发送。
- 扩展欧几里德算法
- 一个很好的排序方法
- android自动弹出软键盘(输入法)
- Leetcode 66. Plus One
- 201. Bitwise AND of Numbers Range
- Salesforce 发送短信信息
- Java IO: System.in, System.out, System.err
- 快速排序-剑指offer
- XZ_iOS之设置label的行间距
- JSP加载MySQL的JDBC驱动
- 谷歌人工智能系统TensorFlow开始支持iOS
- github设置添加SSH
- 权限管理——RBAC模型总结
- JSP连接MySQL