回 楼主skkkkkkkk的帖子
别哭,我今天在写,写好了,发个代码给你看看
-------------------------
Re回 楼主skkkkkkkk的帖子
self.sendAliMessage = function(req,res){
var param = {
'Action' : 'SingleSendSms',
'SignName' : 'xxxx', //短信签名名称
'TemplateCode' : 'SMS_1635xxxx',
'RecNum' : '13564096???', //手机号
'ParamString' : JSON.stringify({"code":"9527"}),//验证码模板里的变量
'Version' : '2016-09-27',
'Format' : 'JSON',
'AccessKeyId' : ali_access_key_id,
'SignatureMethod' : 'HMAC-SHA1',
'SignatureVersion' : '1.0',
'SignatureNonce' : randomstr(9), //随机数
'Timestamp' : new Date().toISOString(),
};
param.Signature = sign.signForAliMessage(param, ali_access_key_secret);
var api_url = 'https://sms.aliyuncs.com/';
request.post({
url: api_url,
headers: {
'Content-Type':'application/x-www-form-urlencoded'
},
form:param
},function(err,response,data){
var result
data = JSON.parse(data);
if (!err && data.Model) {
result = res.returnData(200);
}else{
result = res.returnData(113);
}
res.send(result);
});
}
/*签名方法*/
sign.signForAliMessage = function(src_sign,access_key_secret){
var param , qstring = [];
var oa = Object.keys(src_sign).sort() , on = {};
for(var i=0;i<oa.length;i++){
on[oa
] = src_sign[oa];
}
param = on;
for(var key in param){
qstring.push(encodeURIComponent(key)+'='+encodeURIComponent(param[key]));
}
qstring = qstring.join('&');
var StringToSign = 'POST'+'&'+encodeURIComponent('/')+'&'+encodeURIComponent(qstring);
access_key_secret = access_key_secret+'&';
var signature = crypto.createHmac('sha1', access_key_secret).update(new Buffer(StringToSign, 'utf-8')).digest('base64');
return signature;
}
我已经发送成功了,你照抄就可以了