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

  • 相关阅读:
    12_springmvc拦截器
    11_springmvc之RESTful支持
    10_springmvc JSON数据交互
    09_springmvc图片上传
    09_springmvc异常处理
    08_springmvc数据回显和@ModelAttribute注解详解
    Eclipse-----解决调试源码不进入断点问题
    JavaScript-----截取字符串的常用方法
    排序(Sort)-----冒泡排序
    SpringMVC探究-----常用获取传递参数的方法
  • 原文地址:https://www.cnblogs.com/yanhuiw/p/4863363.html
Copyright © 2011-2022 走看看