国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP接入阿里短信無(wú)法發(fā)送短信
Mr 張
Mr 張 2018-07-26 09:18:28
0
3
1294

源碼如下 ?請(qǐng)求大神指導(dǎo)下 哪里問(wèn)題該如何修復(fù)

頁(yè)面非常簡(jiǎn)潔的 就是用戶提交內(nèi)容 然后通過(guò)阿里云發(fā)送

<?php
include_once("admin_head.php");
getadmin();
$action=isset($_GET['action'])?$_GET['action']:"list";
switch($action){
	
	
	case "qunfa":
		?>
        <div id='test'></div>
		<form style='width:420px;' action='?action=savequnfa' method='post'  onsubmit='return check()' class='myform' enctype='multipart/form-data' >
          <br>
         <span class='myspan' style='width:80px;'>號(hào)碼:</span><textarea name='qunfahaoma' style='width:420px;height:300px;'>群發(fā)的號(hào)碼請(qǐng)用“,”來(lái)間隔,否則將會(huì)失??!</textarea><br/><br/>
         <span class='myspan' style='width:80px;'>內(nèi)容:</span><textarea name='about' style='width:420px;height:100px;'>請(qǐng)勿發(fā)敏感字!</textarea>
  		 <center><input type='submit' value='確認(rèn)發(fā)送' class='submit'></center>
         
        </form>
        
		<?php
		
	$haoma=$_POST['qunfahaoma'];
	//$neirong=$_POST['about'];
	break;
	
	case "savequnfa":
	$haoma=$_POST['qunfahaoma'];
	//print($haoma)
				if($haoma)sendSms("{$_POST['qunfahaoma']}","{$_POST['about']}");
				//短信通知//
				//短信通知//
				//$sendSms=sendSms("{$_POST['qunfahaoma']}","{$_POST['about']}");
				//短信通知//
	
class SignatureHelper{
    public function request($accessKeyId, $accessKeySecret, $domain, $params, $security=false) {
        $apiParams = array_merge(array (
            "SignatureMethod" => "HMAC-SHA1",
            "SignatureNonce" => uniqid(mt_rand(0,0xffff), true),
            "SignatureVersion" => "1.0",
            "AccessKeyId" => $accessKeyId,
            "Timestamp" => gmdate("Y-m-d\TH:i:s\Z"),
            "Format" => "JSON",
        ), $params);
        ksort($apiParams);
        $sortedQueryStringTmp = "";
        foreach ($apiParams as $key => $value) {
            $sortedQueryStringTmp .= "&" . $this->encode($key) . "=" . $this->encode($value);
        }
        $stringToSign = "GET&%2F&" . $this->encode(substr($sortedQueryStringTmp, 1));
        $sign = base64_encode(hash_hmac("sha1", $stringToSign, $accessKeySecret . "&",true));
        $signature = $this->encode($sign);
        $url = ($security ? 'https' : 'http')."://{$domain}/?Signature={$signature}{$sortedQueryStringTmp}";
        try {
            $content = $this->fetchContent($url);
            return json_decode($content);
        } catch( \Exception $e) {
            return false;
        }
    }

    private function encode($str){
        $res = urlencode($str);
        $res = preg_replace("/\+/", "%20", $res);
        $res = preg_replace("/\*/", "%2A", $res);
        $res = preg_replace("/%7E/", "~", $res);
        return $res;
    }

    private function fetchContent($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "x-sdk-client" => "php/2.0.0"
        ));
        if(substr($url, 0,5) == 'https') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        $rtn = curl_exec($ch);
        if($rtn === false) {
            trigger_error("[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR);
        }
        curl_close($ch);
        return $rtn;
    }
}
//短信群發(fā)2018年7月25日17:24:40
function sendSms($tomobile,$code) {
    $params = array ();
    $accessKeyId = "LTAIZbtSes4imVOP";
    $accessKeySecret = "4ncagqiD1b5Twm0wySraxx3Ei***oA";
    $params["PhoneNumbers"] = "18356666163";//原使用變量測(cè)試方便直接使用了號(hào)碼
    $params["SignName"] = "九華一樓";//短信簽名
    $params["TemplateCode"] = "SMS_140525190";//模板CODE
    $params['TemplateParam'] = Array (
        "code" => $code,
    );//模板參數(shù)  
    $params['OutId'] = "";// fixme 可選: 設(shè)置發(fā)送短信流水號(hào)  
    $params['SmsUpExtendCode'] = "";// fixme 可選: 上行短信擴(kuò)展碼, 擴(kuò)展碼字段控制在7位或以下,無(wú)特殊需求用戶請(qǐng)忽略此字段
    /******************自定義部分結(jié)束************************/	
    if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
        $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
    }
    $helper = new SignatureHelper();
    // 此處可能會(huì)拋出異常,注意catch
    $content = $helper->request(
        $accessKeyId,
        $accessKeySecret,
        "dysmsapi.aliyuncs.com",
        array_merge($params, array(
            "RegionId" => "cn-hangzhou",
            "Action" => "SendSms",
            "Version" => "2017-05-25",
        ))
        // fixme 選填: 啟用https
        // ,true
    );
	
ini_set("display_errors", "on"); // 顯示錯(cuò)誤提示,僅用于測(cè)試時(shí)排查問(wèn)題
// error_reporting(E_ALL); // 顯示所有錯(cuò)誤提示,僅用于測(cè)試時(shí)排查問(wèn)題
set_time_limit(0); // 防止腳本超時(shí),僅用于測(cè)試使用,環(huán)境請(qǐng)按實(shí)際情況設(shè)置
header("Content-Type: text/plain; charset=utf-8"); // 輸出為utf-8的文本格式,僅用于測(cè)試

// 驗(yàn)證發(fā)送短信(SendSms)接口
print_r(sendSms());
    return $content;
}
		alert("操作成功!響應(yīng)時(shí)間依據(jù)您的短信數(shù)量和短信通道信號(hào),請(qǐng)耐心等待","?action=qunfa");
	break;
	
}
include_once("admin_foot.php");
?>
Mr 張
Mr 張

全部回復(fù)(2)
Summer

可以打印一下返回結(jié)果看看是哪里出錯(cuò)

  • 回復(fù) 我用echo 或者print 輸出 無(wú)法輸出
    Mr 張 作者 2018-07-26 09:36:56
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板