yunpsmsChajian.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * 来自:信呼开发团队
  4. * 作者:磐石(rainrock)
  5. * 网址:http://www.rockoa.com/
  6. * 云片网短信服务
  7. * 此文件放到:include/chajian/yunpsmsChajian.php 下
  8. * 开发帮助地址:http://www.rockoa.com/view_yunpsms.html
  9. */
  10. class yunpsmsChajian extends Chajian{
  11. private $sendurl = 'https://sms.yunpian.com/v2/sms/batch_send.json';
  12. private $yunpian_key = '你的短信apikey'; //这里填写你的云片网的apikey
  13. /**
  14. * 短信模版写这里的
  15. */
  16. protected function initChajian()
  17. {
  18. $mobian['defyzm'] = '欢迎使用,您的短信验证码为:#code#,为保障系统安全,请勿将验证码和办公系统网址提供给他人,祝您工作愉快。';
  19. $mobian['defsucc'] = '您提交单据(#modename#,单号:#sericnum#)已全部处理完成,可登录系统查看详情。';
  20. $mobian['default'] = '您有单据(#modename#,单号:#sericnum#)需要处理,请登录系统及时去处理。';
  21. $mobian['birthday'] = '尊敬的#name#,今天是#dt#,农历#dtnong#,是您的生日,我们在这里祝您生日快乐。';
  22. $mobian['defnum'] = '您有#applyname#的(#modename#)单据需要您处理,详情:#url#';
  23. $mobian['defurls'] = '您有单据(#modename#,单号:#sericnum#)需要处理,请及时去处理,详情:#url#。';
  24. $mobian['gongsms'] = '您收到一条“#title#”的通知,详情:#url#';
  25. $mobian['meetapply'] = '#optname#发起会议“#title#”在#hyname#,时间#startdt#至#enddt#';
  26. $mobian['meetcancel'] = '#optname#取消会议“#title#”,时间#startdt#至#enddt#,请悉知。';
  27. $mobian['meettodo'] = '会议“#title#”将在#fenz#分钟后的#time#开始请做好准备,在会议室“#hyname#”';
  28. //上面加你的模版
  29. $this->mobianarr = $mobian;
  30. }
  31. /**
  32. * 批量发送短信
  33. * $mobiles 接收人手机号多个,分开
  34. * $qianm 签名
  35. * $tplid 模版编号,在上面initChajian()数组中查找
  36. * $cans 模版中的参数数组
  37. * 例子:c('mysms')->send('15800000000,15800000001','信呼', 'default', array('modename'=>'模块名','sericnum'=>'单号')); 这例子是不需要自己调用,只要短信设置下切换为“我的短信服务”就可以了
  38. */
  39. public function send($mobiles, $qianm, $tplid, $cans=array())
  40. {
  41. //要发送短信的内容
  42. $text = arrvalue($this->mobianarr, $tplid);
  43. if(isempt($text))return returnerror('模版'.$tplid.'不存在');
  44. foreach($cans as $k=>$v)$text = str_replace('#'.$k.'#', $v, $text);
  45. if(isempt($qianm))return returnerror('没有设置短信签名');
  46. if(isempt($this->yunpian_key))return returnerror('没有设置云片网的apikey');
  47. $text = '【'.$qianm.'】'.$text.''; //发的短信
  48. $arr['apikey'] = $this->yunpian_key;
  49. $arr['mobile'] = $mobiles;
  50. $arr['text'] = $text;
  51. $result = c('curl')->postcurl($this->sendurl, $arr);
  52. if(isempt($result))return returnerror('发送失败');
  53. $barr = json_decode($result, true);
  54. $data = arrvalue($barr,'data');
  55. $total_count = 0; //总发送条数
  56. $sendbo = false;
  57. $msg = '';
  58. if(is_array($data))foreach($data as $k=>$rs){
  59. if($rs['code']==0){
  60. $sendbo = true;
  61. }else{
  62. $msg .= $rs['msg'].';';
  63. }
  64. }
  65. //成功
  66. if($sendbo){
  67. return returnsuccess(array(
  68. 'count' => $barr['total_count'],
  69. 'text' => $text,
  70. 'mobile'=> $mobiles,
  71. ));
  72. }else{
  73. return returnerror('发送失败:'.$msg.'('.$text.')', 202);
  74. }
  75. }
  76. }
粤ICP备19079148号