zoukankan      html  css  js  c++  java
  • 阿里云短信

    <?php
    $app_key = "*********";
    $app_secret = "*******************************";
    $request_paras = array(
            'ParamString' => '{"name":"XXXX"}',
            'RecNum' => '18600000000,13500000000',
            'SignName' =>'签名名称', 
            'TemplateCode' => '模板CODE'
            );
    
    $request_host = "http://sms.market.alicloudapi.com";
    $request_uri = "/singleSendSms";
    $request_method = "GET";
    $info = "";
    $content = do_get($app_key, $app_secret, $request_host, $request_uri, $request_method, $request_paras, $info);
    print_r($content); // API返回值
    # print_r($info);  // 系统请求返回信息
    
    function do_get($app_key, $app_secret, $request_host, $request_uri, $request_method, $request_paras, &$info) {
        ksort($request_paras);
        $request_header_accept = "application/json;charset=utf-8";
        $content_type = "";
        $headers = array(
                'X-Ca-Key' => $app_key,
                'Accept' => $request_header_accept
                );
        ksort($headers);
        $header_str = "";
        $header_ignore_list = array('X-CA-SIGNATURE', 'X-CA-SIGNATURE-HEADERS', 'ACCEPT', 'CONTENT-MD5', 'CONTENT-TYPE', 'DATE');
        $sig_header = array();
        foreach($headers as $k => $v) {
            if(in_array(strtoupper($k), $header_ignore_list)) {
                continue;
            }
            $header_str .= $k . ':' . $v . "
    ";
            array_push($sig_header, $k);
        }
        $url_str = $request_uri;
        $para_array = array();
        foreach($request_paras as $k => $v) {
            array_push($para_array, $k .'='. $v);
        }
        if(!empty($para_array)) {
            $url_str .= '?' . join('&', $para_array);
        }
        $content_md5 = "";
        $date = "";
        $sign_str = "";
        $sign_str .= $request_method ."
    ";
        $sign_str .= $request_header_accept."
    ";
        $sign_str .= $content_md5."
    ";
        $sign_str .= "
    ";
        $sign_str .= $date."
    ";
        $sign_str .= $header_str;
        $sign_str .= $url_str;
    
        $sign = base64_encode(hash_hmac('sha256', $sign_str, $app_secret, true));
        $headers['X-Ca-Signature'] = $sign;
        $headers['X-Ca-Signature-Headers'] = join(',', $sig_header);
        $request_header = array();
        foreach($headers as $k => $v) {
            array_push($request_header, $k .': ' . $v);
        }
    
        $ch = curl_init();
    
        curl_setopt($ch, CURLOPT_URL, $request_host . $url_str);
        //curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $ret = curl_exec($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);
        return $ret;
    }
  • 相关阅读:
    基于 jQuery 实现的非常精致的自定义内容滑动条
    异步加载js,Css方法
    jquery ready()的几种实现方法小结
    javascript事件绑定,取消,addEventListener,removeEventListener,attachEvent,detachEvent
    JSONP跨域访问,通过动态加入javascript实现
    抓包
    devops docker笔记
    linux 命令
    ubuntu16 mysql5.7 数据占满磁盘mysql服务停止的恢复方法
    devops kubernates
  • 原文地址:https://www.cnblogs.com/huay/p/10553801.html
Copyright © 2011-2022 走看看