zoukankan      html  css  js  c++  java
  • php 云片国外短信实例

    <?php
    namespace RuifiApp;
    
    
    
    class SmsL
    {
    
        public  function smsIcode($moblie,$sms_code,$intl_code){
            header("Content-Type:text/html;charset=utf-8");
            $apikey = "";
            $mobiles = "+".$intl_code.$moblie;
            $text = "Shixi";
            $smsArrL = array(
                "apikey" => "$apikey",
                "mobile" => "$mobiles",
                "text" =>"$text"
            );
            $smsArrL_to = RuifiServiceCommonService::gbk_to_utf8_arr($smsArrL); //编码转换
            $apikey = $smsArrL_to['apikey'];
            $mobilesm = $smsArrL_to['mobile'];
           /* $mobiles = urlencode("$mobile");
            $mobiles = urlencode("$mobiles");*/
            //$text = $smsArrL_to['text'];
    
    
            $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);
    // 发送短信
          /* $data=array('text'=>$text,'apikey'=>$apikey,'mobile'=>$mobile);
            $json_data = $this->send($ch,$data);
            $array = json_decode($json_data,true);
    
            return $array;*/
    
    // 发送模板短信
    // 需要对value进行编码
            $data = array('tpl_id' => '2009674', 'tpl_value' => ('#code#').
                '='.urlencode("$sms_code"), 'apikey' => $apikey, 'mobile' => $mobilesm);
            $json_data = $this->tpl_send($ch,$data);
            $array = json_decode($json_data,true);
            return $array;
    
    
            curl_close($ch);
        }
    
    
        /************************************************************************************/
    
        function send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            $result = curl_exec($ch);
            $error = curl_error($ch);
            $this->checkErr($result,$error);
            return $result;
        }
        function tpl_send($ch,$data){
            curl_setopt ($ch, CURLOPT_URL,
                'https://sms.yunpian.com/v2/sms/tpl_single_send.json');
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
            $result = curl_exec($ch);
            $error = curl_error($ch);
            $this->checkErr($result,$error);
            return $result;
        }
        function checkErr($result,$error) {
            if($result === false)
            {
                echo 'Curl error: ' . $error;
            }
            else
            {
                //echo '操作完成没有任何错误';
            }
        }
    
    
    }
    

    调用:

    //传递手机号 验证码 和 国家区号
    $SmssL = new RuifiAppSmsL(); $Code = $SmssL->smsIcode("$mobile","$sms_code","$intl_code"); if ($Code['code'] == '0'){ $codeState = 'OK'; }
  • 相关阅读:
    [转]IOS下如何判断机器是否越狱
    [转]php rsa加密解密实例
    『TensorFlow × MXNet』SSD项目复现经验
    『TensorFlow』正则化添加方法整理
    『流畅的Python』第10章笔记_序列类型
    『MXNet』im2rec脚本使用以及数据读取
    『TensorFlow』SSD源码学习_其八:网络训练
    『TensorFlow』SSD源码学习_其七:损失函数
    『TensorFlow』SSD源码学习_其六:标签整理
    『TensorFlow』SSD源码学习_其五:TFR数据读取&数据预处理
  • 原文地址:https://www.cnblogs.com/buxiangxin/p/7773399.html
Copyright © 2011-2022 走看看