zoukankan      html  css  js  c++  java
  • beecloud resrful api test(nodejs)

    直接上代码

    
    /**
     * Created by wyh on 2015/10/8.
     * 参数说明:https://beecloud.cn/doc/
     */
    var https  = require('https');
    var crypto = require('crypto');
    var moment = require('moment');
    var uuid   = require('node-uuid');
    
    var app_id     = 'yourAppId';
    var timestamp  = moment().format('x');
    var app_secret = 'YourAppSecret';
    var app_sign   = crypto.createHash('md5').update(app_id + timestamp + app_secret).digest('hex');
    var channel    = 'ALI_WEB';
    var total_fee  = 1;
    var bill_no    = uuid.v4().split('-').join('');
    console.log(bill_no);
    
    var title       = '图时代充值测试';
    var return_url  = 'visys.cn';
    var show_url    = 'http://www.visys.cn';
    var qr_pay_mode = '0';
    
    var postObj = {
        app_id     : app_id,
        timestamp  : parseInt(timestamp),
        app_sign   : app_sign,
        channel    : channel,
        total_fee  : total_fee,
        bill_no    : bill_no,
        title      : title,
        return_url : return_url,
        show_url   : show_url,
        qr_pay_mode: qr_pay_mode
    };
    
    var postData = JSON.stringify(postObj);
    console.log('postData', postData);
    
    var options = {
        host   : 'apibj.beecloud.cn',
        port   : 443,
        path   : '/1/rest/bill',
        method : 'POST',
        headers: {
            'Content-Type': 'application/json'
        }
    };
    
    var req = https.request(options, function (res) {
        console.log('STATUS: ' + res.statusCode);
        console.log('HEADERS: ' + JSON.stringify(res.headers));
    
        var chunkAll = '';
        res.on('data', function (chunk) {
            chunkAll += chunk;
        });
        res.on('end', function () {
            if(!chunkAll) return;
            try{
                var obj = JSON.parse(chunkAll);
                console.log('url', obj.url);
                console.log('chunkAll' + chunkAll);
            }
            catch(e){
                console.log('err', e);
            }
        });
    });
    
    req.write(postData);
    req.end();
    
    req.on('error', function (e) {
        console.error(e);
    });
    

    附:

    header不能添加content-length

  • 相关阅读:
    sublime & atom 插件
    正则表达式必知必会读书笔记
    前端自动化工具
    CSS3效果收集
    JS 常用功能收集
    【1】Hover 效果收集
    javascript进阶高手必备知识
    ionic 实现仿苹果手机通讯录搜索功能
    ionic2APP 如何处理返回键问题
    三张图搞懂JavaScript的原型对象与原型链
  • 原文地址:https://www.cnblogs.com/yanhuiw/p/4863363.html
Copyright © 2011-2022 走看看