本文为您提供了Node.js语言版本的充值接口接口对接DEMO示例
/**
* 安装依赖:npm install querystring
* 测试执行:node ./test.js
*/
var http = require('http')
var querystring = require('querystring');
function post(hostname, path, post_data, callback){
var options = {
hostname: hostname,
port: 80,
path: path,
method: 'POST',
headers: {
'Content-Type':'application/x-www-form-urlencoded',
}
}
var req = http.request(options, function(res){
var body ="";
res.setEncoding('utf8');
res.on('data', function(chunk){
//console.log(chunk.toString());
body += chunk;
});
res.on('end', function(){
var json = JSON.parse(body);
callback(json)
});
});
req.on('error', function(e){
console.log('msg:'+e.message);
});
req.write(post_data);
req.end();
}
var hostname = "api.ihuyi.com";
var request_uri = "/f/recharge?action=buy";
//定义请求的数据
var values = {
"username":"123456", //API ID
"orderid":"DD20253995959", //商家订单 ID
"timestamp":"20240321150546", //时间戳格式如:yyyyMMddHHmmss 允许 10分钟统一以东 8 时间
"account":"xxxxxxx", //充值账号
"productid":"k111-1", //产品 ID
"quantity":"1", //购买数量-固定数量1
"extend":"[]", //扩展参数(必须 json 格式,无此值请保持为“[]”),针对不同商品可能不同,参见 8.扩展参数说明
"return":"", //商家自定义参数,回调回传
"callback":"http://*****", //商家回调 url 地址
"buyerip":"", //买家真实 IP(区域商品须传)
"sign":"81ed625f338277f1bd7f27b9339e302c", //签名
}
var post_data = querystring.stringify(values);
//发起请求
post(hostname, request_uri, post_data, function(json){
//打印结果
console.log(json);
})
在线咨询
150,000家
企业客户
21年
行业经验
2V1
2对1客户支持