开发者社区> 问答> 正文

邮件通知的 API前面算法到底是怎么样的我写的有什么问题么

<?php

function b1Decode($p)
{
    $a = urlencode($p);
    $b = str_replace('+', '%20', $a);
    $c = str_replace('*', '%2A', $b);
    $d = str_replace('%7E', '~', $c);
    return $d;
}


date_default_timezone_set('UTC');

$pubParams = array(
    'Format' => 'JSON',
    'Version' => '2015-11-23',
//
    'AccessKeyId' => 'id',
//    'Signature' => '',
    'SignatureMethod' => 'HMAC-SHA1',
    'Timestamp' => date(DATE_ISO8601),
    'SignatureVersion' => '1.0',
    'SignatureNonce' => uniqid(),
    'Action' => 'SingleSendMail',
//
    'AccountName' => 'aaa@aaa',
    'ReplyToAddress' => true,
    'AddressType' => '1',
//
    'ToAddress' => 'aaa@live.com',
    'Subject' => '4',
    'TextBody' => '4'
);

function getSign($pubParam)
{

    $a = '';

    foreach ($pubParam as $k => $v) {
        if ($a == '') {
            $a .= "{$k}=" . b1Decode($v);
        } else {
            $a .= "&{$k}=" . b1Decode($v);
        }
    }

    return $a;
}


$StringToSign = 'POST&%2F&' . rawurlencode(str_replace('/', '%2F', getSign($pubParams)));


$Signature = base64_encode(hash_hmac("sha1", $StringToSign, 'sk' . '&', true));
$Signature = rawurlencode($Signature);

$url = "https://dm.aliyuncs.com/";
$post_data = 'Signature=' . $Signature . '&' . getSign($pubParams);


//print_r($post_data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);

print_r($output);


展开
收起
gclove 2015-12-03 20:50:23 8503 0
2 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Spring Boot2.0实战Redis分布式缓存 立即下载
CUDA MATH API 立即下载
API PLAYBOOK 立即下载