客客威客短信接口修改(kppw) 配置

最近又一个客户让我帮弄一下客客威客的短信接口,关于客客威客的短信接口的修改,短信接口用的是56短信网短信接口(http://www.56dxw.com),采用的是httpMd5加密接口,程序已经调试通过,现在分享给大家,如果在不明白可以加微信:jjzaihaozhe

1.首先在安装插件或修改代码的,先备份把您要修改或替换的文件进行备.

2.编写调用短信接口的核实代码(Dxw56Sms.php),代码如下:

<?php

/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2016/5/30
 * Time: 12:48
 */
class Dxw56Sms
{
   const URL = 'http://jiekou.56dxw.com/';
    public static function sendSms($userName, $password, $mobile='', $content='')
    {
        $password = md5($password);
        $content =urlencode(mb_convert_encoding($content, 'gbk' ,'utf-8'));
        $sendUrl = self::URL . 'sms/HttpInterfaceMoreMd5.aspx?username='.$userName.'&userpwd='.$password.'&handtel='.$mobile.'&sendtime=&smsnumber=10690&comid=462&sendcontent='.$content;

        $ret = file_get_contents($sendUrl);

        if (1!= $ret) {
            return false;
        }

        return true;
    }
}

3.找到网站中的keke_msg_class.php文件,目录:\lib\inc,用以下代码替换,代码如下:

<?php
keke_lang_class::load_lang_class('keke_msg_class');
require (dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Dxw56Sms.php');
class keke_msg_class {
	public $_key;
	public $_k;
	public $_v=array("send_sms"=>null,"send_email"=>null,"send_mobile_sms"=>null);
	public $_title;
	public $_config;
	public $_uid;
	public $_username;
	public $_sitename;
	public $_normal_content;
	public $_mobile_content;
	public $_email;
	public $_mobile;
	public $_type;
	public $_basicconfig;
	function __construct() { 
		$this->basic_init ();
	}
	function basic_init() {
		global $_lang;
		global $basic_config;
		$this->_basicconfig = $basic_config;
		$this->_key = array ();
		$this->_title = $_lang['msg_notice'];
		$this->_k = "";
		$this->_sitename = $basic_config ['website_name'];
	}
	function config_init($k) {
		$this->_k = $k;
		$this->_config = db_factory::get_one ( " select * from " . TABLEPRE . "witkey_msg_config where k='$k'" );
		$this->_v = unserialize ( $this->_config ['v'] );
	}
	function setUid($uid) {
		$this->_uid = $uid;
	}
	function setUsername($username) {
		$this->_username = $username;
	}
	function setTitle($title) {
		$this->_title = $title;
	}
	function setType($type) {
		$this->_type = $type;
	}
	function setEmail($email) {
		$this->_email = $email;
	}
	function setValue($key, $value) {
		$this->_key [$key] = $value;
	}
	function setMobile($str_mobile) {
		$this->_mobile = $str_mobile;
	}
	function validate($k) {
		$this->config_init ( $k );
		if(is_array( $this->_v)){
			if (array_sum ( $this->_v ) <= 0) {
				return false;
			} else {
				return true;
			}
		}
	}
	function send() {
		if (! $this->_uid) {
			return false;
		}
		if (! $this->validate ( $this->_k )) {
			return false;
		}
		$this->pregmessage ( $this->_k );
		$sum = array_sum ( $this->_v );
		switch ($sum) {
			case 1 :
				($this->_v ['send_sms'] == 1) and $this->sendmessage ();
				(isset($this->_v ['send_email'])&& $this->_v ['send_email']== 1) and $this->sendmail ();
				(isset($this->_v ['send_mobile_sms'])&& $this->_v ['send_mobile_sms'] == 1) and $this->send_phone_sms ();
				break;
			case 2 :
				(($this->_v ['send_sms'] == 1 && $this->_v ['send_email'] == 1)) and ($this->sendmessage () or $this->sendmail ());
				(($this->_v ['send_sms'] == 1 && $this->_v ['send_mobile_sms'] == 1)) and ($this->sendmessage () or $this->send_phone_sms ());
				(($this->_v ['send_mobile_sms'] == 1 && $this->_v ['send_email'] == 1)) and ($this->sendmail () or $this->send_phone_sms ());
				break;
			case 3 :
				$this->sendmessage ();
				$this->sendmail ();
				$this->send_phone_sms ();
				break;
		}
		$this->_key = array ();
	}
	private function getmessagetpl() {
		global $_cache_obj;
		$tpl = $_cache_obj->get ( "msg_tpl_" . $this->_k . "_cache" );
		if (! $tpl) {
		    $objMsgConfig = new Keke_witkey_msg_config_class();
		    $objMsgConfig->setWhere("k='$this->_k'");
		    $tpl = $objMsgConfig->query_keke_witkey_msg_config();
		    $_cache_obj->set ( "msg_tpl_" . $this->_k . "_cache", $tpl );
		}
		return $tpl;
	}
	private function pregmessage() {
		$tpl = $this->getmessagetpl ();
		if (! $this->_username) {
			$userinfo = kekezu::get_user_info ( $this->_uid );
			$this->_username = $userinfo ['username'];
		}
		$cont0 = $tpl [0] ['content'];
		$cont0 = $this->tpl_format ( $cont0 );
		$this->_normal_content = $cont0;
		$cont1 = $tpl [0] ['mobile_content'];
		$cont1 = $this->tpl_format ( $cont1 );
		$this->_mobile_content = $cont1;
	}
	private function tpl_format($content) {
		global $_lang;
		$this->_username and $cont = str_replace ( '{' . $_lang['username'] . '}', $this->_username, $content );
		$this->_uid and $cont = str_replace ( '{' . $_lang['user_id'] . '}', $this->_uid, $cont );
		$this->_sitename and $cont = str_replace ( '{' . $_lang['website_name'] . '}', $this->_sitename, $cont );
		foreach ( $this->_key as $k2 => $v2 ) {
			$cont = str_replace ( '{' . $k2 . '}', $v2, $cont );
		}
		return $cont;
	}
	private function sendmessage() {
		$message_obj = new Keke_witkey_msg_class ();
		$message_obj->setTitle ( $this->_title );
		$message_obj->setContent ( $this->_normal_content );
		$message_obj->setTo_uid ( $this->_uid );
		$message_obj->setTo_username ( $this->_username );
		$message_obj->setType ( $this->_type );
		$message_obj->setOn_time ( time () );
		$res = $message_obj->create_keke_witkey_msg ();
	}
	public function sendmail() {
		global $_K;
		if (! $this->_email || ! $this->_username) {
			$userinfo = kekezu::get_user_info ( $this->_uid );
			$this->_username = $userinfo ['username'];
			$this->_email = $userinfo ['email'];
		}
		if (! $this->_email) {
			return false;
		}
		$this->_basicconfig and $basicconfig = $this->_basicconfig or $basicconfig = kekezu::get_config ( 'basic' );
		if ($basicconfig ['mail_server_cat'] == 'mail') {
			if ($basicconfig ['post_account'] && $basicconfig ['mail_replay'] && $this->_email && $this->_title && $this->_normal_content) {
				$hearer = "From:{$basicconfig['post_account']}\nReply-To:{$basicconfig['mail_replay']}\nX-Mailer: PHP/" . phpversion () . "\nContent-Type:text/html";
				mail ( $this->_email, $this->_title, htmlspecialchars_decode($this->_normal_content), $hearer );
			}
		} else if ($basicconfig ['smtp_url'] && $basicconfig ['mail_server_port'] && $basicconfig ['post_account'] && $basicconfig ['account_pwd'] && $basicconfig ['website_name']) {
			kekezu::send_mail ( $this->_email, $this->_title, htmlspecialchars_decode($this->_normal_content) );
		}
	}
	public function send_phone_sms( $mobiles = '', $tar_content = '') {

		global $basic_config;
		if($basic_config['sms_interface'] != 'open'){
			return false;
		}

		$res = db_factory::query('select * from ' . TABLEPRE . 'witkey_basic_config where type="mobile"');

		if (empty($res)) {
			return false;
		}

		$res = $this->getUserInfo($res);

		if (empty($res)) {
			return false;
		}

		!$mobiles and $mobiles = $this->_mobile;
		!$tar_content and $tar_content = $this->_mobile_content;
		$tar_content = strip_tags(htmlspecialchars_decode($tar_content));

		return Dxw56Sms::sendSms($res['username'], $res['password'], $mobiles, $tar_content);
	}

	private function getUserInfo($res)
	{
		$retArr = array();

		foreach ($res as $item) {
			if ('mobile_username' == $item['k']) {
				$retArr['username'] = $item['v'];
			} else if ('mobile_password' == $item['k']) {
				$retArr['password'] = $item['v'];
			} else {
				continue;
			}
		}

		if (!isset($retArr['username']) || !isset($retArr['password'])) {
			return false;
		}

		return $retArr;
	}

	public function send_message($uid, $username, $action, $title, $v_arr = array(), $email = null, $mobile = null,$type=null) {
		if ($this->validate ( $action )) {
			$this->setUid ( $uid );
			$this->setUsername ( $username );
			$this->setEmail ( $email );
			$this->setMobile ( $mobile );
			$this->setType ( $type ?$type:'2');
			foreach ( $v_arr as $k => $v ) {
				$this->setValue ( $k, $v );
			}
			$this->setTitle ( $title );
			$this->send ();
		}
	}
	public static function send_private_message($title, $tar_content, $to_uid, $to_username, $url = '', $output = 'normal') {
		global $uid, $username;
		global $_lang;
		if (CHARSET == 'gbk') {
			$title = kekezu::utftogbk ( $title );
			$tar_content = kekezu::utftogbk ( $tar_content );
			$to_username = kekezu::utftogbk ( $to_username );
		}
		$msg_obj = new Keke_witkey_msg_class ();
		$msg_obj->_msg_id = null;
		$msg_obj->setUid ( $uid );
		$msg_obj->setUsername ( $username );
		$msg_obj->setTitle ( $title );
		$msg_obj->setTo_uid ( $to_uid );
		$msg_obj->setTo_username ( $to_username );
		$msg_obj->setContent ( $tar_content );
		$msg_obj->setOn_time ( time () );
		$msg_obj->setType(2);
		return  $msg_obj->create_keke_witkey_msg ();
	}
	public static function notify_user($uid, $username, $action, $title, $v_arr = array(),$type=null) {
		$msg_obj = new keke_msg_class ();
		$contact = self::get_contact ( $uid );
		if(!$username) $username = $contact['username'];
		$msg_obj->send_message ( $uid, $username, $action, $title, $v_arr, $contact ['email'],$contact ['mobile'],$type);
	}
	public static function get_contact($uid) {
		return db_factory::get_one ( sprintf ( " select `username`,mobile,email from %switkey_space where uid = '%d'", TABLEPRE, $uid ) );
	}
}

3.现在的短信必须加上签名,如果您想修改自己网站的签名,文件名:keke_auth_mobile_class.php 目录:\lang\cn\public,也可以修改一下发送的短信内容.如图


4.全局配置 -> 短信接口,开启并添写短信接口用户名,密码,如图


5.根据需要开启相应的发送短信功能,如图:


6.开启之后,就可以实现短信的发送了,比如:对会员中心手机进行认证,手机认证成功后,提示如图所示:



在这里之所以把代码给大家贴出来,是为了更加灵活的适用于各个版本,其实不论那个版本,做相应的修改是就可以了,还是非常简单的,当然,如果各位朋友还有不明白的,可以加我微信:jjzaihaozhe

可能写的还有一些不足之后,也欢迎大家批评,共同讨论啊,哈。。



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值