短信签名快速报备,马上注册寻求客户经理支持!
所有文档
文档中心 > 数字权益 > 数字权益卡密取卡

数字权益卡密取卡

Node.js对接充值接口接口DEMO示例

本文为您提供了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/giftcard?action=buy";

//定义请求的数据
var values = {
    "username":"123456", //API ID
    "mobile":"130*******", //手机号
    "orderid":"DD20253995959", //商家订单ID
    "productid":"k111-1", //产品ID
    "buynum":"1", //购买数量-固定数量1
    "timestamp":"20240321150546", //时间戳格式如:yyyyMMddHHmmss 允许 10分钟统一以东 8 时间
    "sign":"81ed625f338277f1bd7f27b9339e302c", //签名
}
var post_data = querystring.stringify(values);

//发起请求
post(hostname, request_uri, post_data, function(json){
    //打印结果
    console.log(json);
})

在线咨询
服务热线:
4008 808 898

免费体验

提交成功
若短信发送异常,系统将自动给您发送语音验证码,请注意接听电话。

填写验证码后,点击“开通体验账户”自动开通体验账户。

收不到短信验证码?
×