当前位置: 首页 > article >正文

最土团购短信接口错误码和中文乱码问题

最土团购短信接口是最土团购程序的一个集成功能可以连接到短信服务商提供的api发送短信。但是很多用户在使用过程中都遇到了问题,最土团购短信接口比较常见的有:

    1. 发送短信失败,错误码:-2
    2. 发送短信失败,错误码:-10

      之类的,在解决这些问题之前你要知道你使用的是哪个短信服务商,因为不同服务商的短信服务api接口地址是不一样的。
      而最土团购程序里面的api接口默认是官方提供的:

      1 $api = "http://notice.zuitu.com/sms?user={$user}&pass={$pass}&phones={$phone}&content={$content}";> 

      但有的用户下载的可能不是官方原版的程序api接口可能被修改过过导致连接不上短信接口而产生错误,修改方法依次进入目录:include\function\sms.php 第22行就可以修改了,这里改成你申请的短信api就可以了。

      还有一个就是短信发送出去后可能会产生中文乱码问题,这是因为编码问题,把编码转换成utf8就可以解决。

      在第21行替换代码:

      $content = urlEncode(mb_convert_encoding($content,'GBK','UTF-8'));

      示例代码(官方API)

      <?php 
      function sms_send($phone, $content) { global $INI; if (mb_strlen($content, 'UTF-8') < 20) { return '短信长度低于20汉字?长点吧~'; } /* include customsms function */ $smsowner_file = dirname(__FILE__) . '/smsowner.php'; if (file_exists($smsowner_file)) {  require_once( $smsowner_file); if(function_exists('sms_send_owner')) { return sms_send_owner($phone, $content); } } /* end include */ $user = strval($INI['sms']['user']); $pass = strtolower($INI['sms']['pass']); if(null==$user) return true; //$content = urlEncode(mb_convert_encoding($content,'GBK','UTF-8'));//如果为gbk去掉注释 $api = "http://notice.zuitu.com/sms?user={$user}&pass={$pass}&phones={$phone}&content={$content}"; $res = Utility::HttpRequest($api); return trim(strval($res))=='0' ? true : strval($res); 
      } function sms_secret($mobile, $secret, $enable=true) { global $INI; $funccode = $enable ? '订阅' : '退订'; $content = "{$INI['system']['sitename']},您的手机号:{$mobile} 短信{$funccode}功能认证码:{$secret}。"; sms_send($mobile, $content); 
      } function sms_bind($mobile, $secret) { global $INI; $content = "{$INI['system']['sitename']},您的手机号:{$mobile} 绑定码:{$secret}。"; sms_send($mobile, $content); 
      } function sms_coupon($coupon, $mobile=null) { global $INI; if ( $coupon['consume'] == 'Y'  || $coupon['expire_time'] < strtotime(date('Y-m-d'))) { return $INI['system']['couponname'] . '已失效'; } $user = Table::Fetch('user', $coupon['user_id']); $order = Table::Fetch('order', $coupon['order_id']); if (!Utility::IsMobile($mobile)) { $mobile = $order['mobile']; if (!Utility::IsMobile($mobile)) { $mobile= $user['mobile']; } } if (!Utility::IsMobile($mobile)) { return '请设置合法的手机号码,以便接受短信'; } $team = Table::Fetch('team', $coupon['team_id']); $partner = Table::Fetch('partner', $coupon['partner_id']); $coupon['end'] = date('Y-n-j', $coupon['expire_time']); $coupon['name'] = $team['product']; $content = render('manage_tpl_smscoupon', array( 'partner' => $partner, 'coupon' => $coupon, 'user' => $user, )); if (true===($code=sms_send($mobile, $content))) { Table::UpdateCache('coupon', $coupon['id'], array( 'sms' => array('`sms` + 1'), 'sms_time' => time(), )); return true; } return $code; 
      } function sms_voucher($voucher, $mobile=null) { global $INI; $user = Table::Fetch('user', $voucher['user_id']); $order = Table::Fetch('order', $voucher['order_id']); if (!Utility::IsMobile($mobile)) { $mobile = $order['mobile']; if (!Utility::IsMobile($mobile)) { $mobile= $user['mobile']; } } if (!Utility::IsMobile($mobile)) { return '请设置合法的手机号码,以便接受短信'; } $team = Table::Fetch('team', $voucher['team_id']); $partner = Table::Fetch('partner', $team['partner_id']); $voucher['end'] = date('Y-n-j', $team['expire_time']); $voucher['name'] = $team['product']; $content = render('manage_tpl_smsvoucher', array( 'partner' => $partner, 'voucher' => $voucher, 'user' => $user, )); if (true===($code=sms_send($mobile, $content))) { Table::UpdateCache('voucher', $voucher['id'], array( 'sms' => array('`sms` + 1'), 'sms_time' => time(), )); return true; } return $code; 
      } function sms_express($id, &$flag=null) { $order = Table::Fetch('order', $id); $team = Table::Fetch('team', $order['team_id']); if (!$order['express_id']) { $flag = 'No express'; return false; } $express = Table::Fetch('category', $order['express_id']); $html = render('manage_tpl_smsexpress', array( 'team' => $team, 'express_name' => $express['name'], 'express_no' => $order['express_no'], )); $phone = $order['mobile']; if ( true === ($flag = sms_send($phone, $html)) ) { Table::UpdateCache('order', $id, array( 'sms_express' => 'Y', )); return true; } return false; 
      }

       

http://www.lryc.cn/news/2413608.html

相关文章:

  • ubuntu 12.04 server 安装
  • 推荐使用:快速构建LINE机器人的利器 —— LINE Messaging API SDK for Ruby
  • Wine的完全使用指南
  • 飞思卡尔智能车经验
  • 寒霜系列引擎技术解析
  • 无需设计技能,AI让你秒变LOGO大师!
  • 为U盘安装即插即用的kali(linux)操作系统(超级详细~)
  • 思科路由器及交换机基本配置
  • 渗透学习(3)局域网攻击
  • 电脑系统提示找不到d3d8.dll文件如何解决?
  • 大数据分析题-考试竞赛(分享)
  • 网络知识点之-详解robots协议
  • Mozilla Firefox 4.0 Beta 6 RC发布
  • 快速上手 Vue 和 Element-UI 组件库
  • 来往网页版扫码自动登录的实现原理(微信也是一样)
  • MFC消息机制 Qt消息机制 解析
  • codeblocks 汉化包+汉化教程,仅需三步
  • 从零开始如何制作在线商城网站?流程步骤与常见问题全攻略
  • PHP配置FCKeditor编辑器以及上传图片
  • 张刚山东首富 哲商对话·中国儒商大会:2023胡润全球富豪榜
  • 基于51单片机的无线病床呼叫系统设计
  • bzoj1033 [ZJOI2008]杀蚂蚁antbuster
  • 地铁跑酷:解锁所有关卡的金币和钥匙收集指南
  • scripto.dll文件丢失导致程序无法运行问题
  • HTML如何设置文本域的大小
  • Zend Studio 9 汉化教程
  • Ubuntu 13.10安装ICE
  • 【Windows Server 2019】DNS服务器的配置与管理——DNS子域委派
  • 为pdf文件增加金山取词功能
  • svn配置