最土团购短信接口错误码和中文乱码问题
最土团购短信接口是最土团购程序的一个集成功能可以连接到短信服务商提供的api发送短信。但是很多用户在使用过程中都遇到了问题,最土团购短信接口比较常见的有:
- 发送短信失败,错误码:-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; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构