Fanwe 方维多语商城建站系统接入手机短信功能--支持注册验证、订单通知等

一、安装方法
1.在后台数据库->SQL操作下添加短信平台
INSERT INTO fanwe_sms (class_name,name) VALUES ('ihuyi','互亿无线短信平台')
2.在后台邮件短信->短信平台列表 修改帐号密码,网址等(http://106.ihuyi.cn/webservice/sms.php?method=Submit)
3.将ihuyiSms.class.php文件上传到services/Sms/目录下就ok了

二、账户申请及接口下载
1.短信账户申请地址: http://www.ihuyi.com/product.php?cid=33 

2.接口文件下载地址:http://www.ihuyi.com/upload/file/cu-fa-jie-kou.rar;请仔细阅读《接口文档--必须看!!!!.doc》。 

3.完整代码下载:http://www.ihuyi.com/upload/file/FanWe CMS.rar


三、注意事项
1、覆盖文件之前,请事先做好备份
2、免费调试期间,请按照《接口文档--必须看!!!!.doc》的说明,用系统默认模板进行调试。

3、成为正式用户之后方可发送您指定的短信内容。


四、代码

<?php
// +----------------------------------------------------------------------
// | Fanwe 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.fanwe.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: awfigq(67877605@qq.com)
// +----------------------------------------------------------------------
// | 短信接口帐户免费申请:http://www.ihuyi.com/product.php
// +----------------------------------------------------------------------
include_once("Sms.class.php");
include_once(ROOT_PATH."ThinkPHP/Vendor/transport.php");

class ihuyiSms implements Sms
{
	public $config = array(
		"ecode"=>"",
	);	
	public $message = "";
	public $smsInfo;
	
    public function __construct($smsInfo = '')
    { 	
		if(!empty($smsInfo))
		{
			set_time_limit(0);
			
			$this->smsInfo = $smsInfo;
		}
    }
	
	function xml_to_array($xml){
		$reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
		if(preg_match_all($reg, $xml, $matches)){
			$count = count($matches[0]);
			for($i = 0; $i < $count; $i++){
			$subxml= $matches[2][$i];
			$key = $matches[1][$i];
				if(preg_match( $reg, $subxml )){
					$arr[$key] = $this->xml_to_array( $subxml );
				}else{
					$arr[$key] = $subxml;
				}
			}
		}
		return $arr;
	}

	public function sendSMS($mobiles=array(),$content,$sendTime='')
	{
		$mobileLen = 200;
		$messageLen = 170;
		//if($this->smsInfo['config']['contentType'] == 8)
			//$messageLen = 500;
			
		$content = a_utf8ToGB($content);
		$contentLen = mb_strlen($content,"GBK");
		$smsTotalCount = ceil($contentLen / $messageLen) * count($mobiles);
		
		$mobileList = array_chunk($mobiles,$mobileLen);
		$successNum = 0;

		foreach($mobileList as $mobileItem)
		{
			$smsCount = ceil($contentLen / $messageLen);
			$mobile = implode(",",$mobileItem);
			
			for($i=0;$i < $smsCount;$i++)
			{
				$msg = mb_substr($content,$i * $messageLen,$messageLen,"GBK");
				
				$sms = new transport();
				$sms->use_curl = true;
				$params = array(
					"account"=>$this->smsInfo['user_name'],	
					"password"=>$this->smsInfo['password'],	
					"mobile"=>$mobile,
					"content"=>urlencode($msg)
				);
// 短信接口帐户申请:http://www.ihuyi.com/product.php
			
				$result = $sms->request($this->smsInfo['server_url'],$params);
				$smsStatus = $this->xml_to_array($result['body']);

				$code = $smsStatus['SubmitResult']['code'];
				
				$smsLog['send_content'] = a_gbToUtf8($msg);


				$smsLog['action_message'] = "code:".$code.";".$smsStatus['SubmitResult']['msg'];
				$sendCount = count($mobileItem);
				
				if($code == "2")
				{
					$smsLog['success_mobiles'] = $mobile;
					$smsLog['fail_mobiles'] = "";
					$smsLog['success_count'] = $sendCount;
					$smsLog['fail_count'] = 0;
					
					$sendStrLen = mb_strlen($msg,"GBK");
					$smsLog['expense_count'] = ceil($sendStrLen / 67) * $sendCount;

					$successNum += $sendCount;
				}
				else
				{
					$smsLog['success_mobiles'] = "";
					$smsLog['fail_mobiles'] = $mobile;
					$smsLog['success_count'] = 0;
					$smsLog['fail_count'] = $sendCount;
					$smsLog['expense_count'] = 0;
				}
				
				$smsLog['send_time'] = a_gmtTime();
				
				if(intval(a_fanweC('SMS_SEND_LOG')) == 1)
				{
					$sql = "insert into ".$GLOBALS['db_config']['DB_PREFIX']."sms_send_log (class_name,send_content,success_count,success_mobiles,fail_mobiles,expense_count,fail_count,action_message,send_time) values('ihuyi','".$smsLog['send_content']."','".$smsLog['success_count']."','".$smsLog['success_mobiles']."','".$smsLog['fail_mobiles']."','".$smsLog['expense_count']."','".$smsLog['fail_count']."','".$smsLog['action_message']."','".$smsLog['send_time']."')";
					
					$GLOBALS['db']->query($sql);
				}
			}
		}
		if($smsTotalCount > $successNum)
		{
			$this->message = $smsTotalCount."条短信中,有".($smsTotalCount - $successNum)."条未成功发送到手机".implode(",",$mobiles);
			return 0;
		}
		else
		{
			$this->message ="成功发送短信【".$content."】,到手机".implode(",",$mobiles);
			return 1;
		}
	}

}
?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值