• 阿里云短信


    <?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;
    }
  • 相关阅读:
    分布式事务 小结
    分布式事务的CAP理论 与BASE理论
    乐观锁与悲观锁
    CentOS7中DHCP配置
    pandas 学习(2): pandas 数据结构之DataFrame
    pandas 学习(1): pandas 数据结构之Series
    NumPy 学习(3): 通用函数
    NumPy 学习(2): 数组的操作
    NumPy 学习(1): ndarrays
    在Windows宿主机中连接虚拟机中的Docker容器
  • 原文地址:https://www.cnblogs.com/huay/p/10553801.html
Copyright © 2020-2023  润新知