74cms 骑士招聘网 叮咚云短信接入 修改示例

首先感谢一下74cms.com开发的开源招聘程序。不过开发出来的程序连基础的功能都无法使用。程序强制用户必须使用短信认证,但是连基础的短信认证都无法使用。还有很多bug,我们这里就不吐槽了。

靖江人力资源网

下面我们给出叮咚云的类代码(有待完善),文件位置:/Application/Common/qscmslib/sms/dingdongyu/dingdongyu.class.

74CMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www..com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 
// +----------------------------------------------------------------------
// | ModelName: 叮咚鱼短信接口
// +----------------------------------------------------------------------
class dingdongyu_sms{
	protected $_error = 0;
	protected $setting = array();
	public function __construct($setting) {
		$this->setting = $setting;
	}
	/**
	 * 发送模板短信
	 * @param    string     $type 短信通道 手机号码集合,用英文逗号分开
	 * @param    array      $option['mobile':手机号码集合,用英文逗号分开,'content':短信内容]
	 * @return   boolean
	 */
	public function sendTemplateSMS($type='captcha',$option){
                $option = $this->replaceSMSTpl($option);
		$send_arr['apikey'] = $this->setting['appkey'];
		//解析模板内容
		if($option['data']){
                    foreach ($option['data'] as $key => $val) {
                        $data['{'.$key.'}'] = $val;
                    }
                    $data['msg'] = strtr($option['tpl'],$data);
                }else{
                    $data['msg'] = $option['tpl'];
                }
                $send_arr['content'] = '【'.$this->setting['signature'].'】'.$data['msg'];
		$send_arr['mobile'] = $option['mobile'];
		$ch = curl_init();
		/* 设置验证方式 */
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
		/* 设置返回结果为流 */
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		/* 设置超时时间*/
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);
		/* 设置通信方式 */
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		$json_data = $this->send_yzm($ch,$send_arr);
		$result = json_decode($json_data,true);
		curl_close($ch);
		if ($result['code']==1){
			return true;
		}else{
			$this->_error = $result['code'].'短信发送失败,请联系服务商!';
			return false;
		}
	}
	public function getError(){
		return $this->_error;
	}
	//验证码
	protected function send_yzm($ch,$data){
	    curl_setopt ($ch, CURLOPT_URL, 'https://api.dingdongcloud.com/v1/sms/sendyzm');
	    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
	    return curl_exec($ch);
	}
        
        protected function replaceSMSTpl($option){
            if( $option['tpl'] == '您正在登录{变量1}的会员,手机验证码为:{变量2},此验证码有效期为10分钟'      ||
                $option['tpl'] == '您正在注册{变量1}的会员,手机验证码为:{变量2},此验证码有效期为10分钟'      ||
                $option['tpl'] == '您正在找回{变量1}的会员密码,手机验证码为:{变量2},此验证码有效期为10分钟'
            ){
                $option['tpl'] = str_replace(array('{变量1}','{变量2}'), array($option['data']['sitename'],$option['data']['rand']), $option['tpl']);
            }
            
            if( $option['tpl'] == '感谢您使用{变量1}手机认证,验证码为:{变量2}'){
                 $option['tpl'] = str_replace(array('{变量1}','{变量2}'), array($option['mobile'],$option['data']['rand']), $option['tpl']);
               
            }
            
            
            return $option;
            
            
        }
}

 

搬瓦工,年付$49.99CN2高速线路,1024MB内存/1000GB流量/1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr月付$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

发表评论

电子邮件地址不会被公开。 必填项已用*标注