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

最土团购短信接口是最土团购程序的一个集成功能可以连接到短信服务商提供的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; 
      }

       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值