Git Product home page Git Product logo

alipay's Introduction

node.js 实现支付宝 api 包括 担保交易收款即时到帐收款双功能收款网银支付即时到账批量退款支付宝确认发货

用法

npm install alipay
cd test
node app

# http://localhost:3000

代码说明:

alipay_config.js # 设置参数
app.js 中 require('./alipay_config').alipay.route(app) # 设置了支付宝通知路由
alipaydemo.js    # 使用事件处理交易状态等

alipay's People

Contributors

leeqiang avatar lodengo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alipay's Issues

这个是目前最好用的alipay接口么?

需要在nodejs上实现手机网站支付接口,github上有很多nodejs支付宝接口,但这个是被star最多的,可好像没人维护了。过来的人可否知道目前是这个最好用的么?或者说是有谁的fork是比较靠谱的?谢谢!

getSignVeryfy BUG

aliplay_notify.class.js里AlipayNotify.prototype.getSignVeryfy函数中有一个BUG

var prestr = createLinkstring(para_sort);
应改为
var prestr = core_funcs.createLinkstring(para_sort);

关于getResponse的异步问题

AlipayNotify.prototype.verifyNotify = function(_POST){
if(Object.keys(_POST).length == 0) {//判断POST来的数组是否为空
return false;
}
else{
//生成签名结果
var isSign = this.getSignVeryfy(_POST, _POST["sign"]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
var responseTxt = 'true';
if (null != _POST["notify_id"]) {
responseTxt = this.getResponse(_POST["notify_id"]);
}

    //验证
    //responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
    //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
    if (responseTxt == 'true' && isSign) { //preg_match("/true/i",responseTxt)
        return true;
    } else {
        return false;
    }
}

}

由于getResponse是异步调用,当getResponse被调用时,responseTxt的值将不确定,因为getResponse方法无返回值~

verifyUrl实践中的问题

严格来说这不是一个BUG,极有可能是支付宝改了规则,而没有即时修改代码,就是下面这两行代码,也是aliplay_notify.class.js里
this.http_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&';
this.http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?';
先说问题吧,如果不改现在的支付宝,当支付成功后回调回来时候就会挂掉。经与支付宝沟通后,这个问题是这样的,notify.alipay.com/trade/notify_query.do这个接口不能在443端口下工作,他倒是可以在80端口下工作,但我不知道返回结果是怎样的,支付宝推荐使用https那个URL,而且他是支持443端口的,所以我就不管是否是http服务器,都使用https的notify,另外如果能使用https服务器就用https服务器,我倒是想用,但是不知道如何分发证书

签名不正确

个人在使用时对比了一下php的接口,发现在createLinkstring函数内比php的多了一个substring操作。

我自己在调用接口时,必须把substring后面的-2参数改为-1,否则支付宝端一直报签名错误的信息。

test运行失败,麻烦帮忙看看,多谢

配置好partner和key之后,运行担保交易的结果如下:

Express server listening on port 3000
GET / 200 30ms - 407
HEAD / 200 5ms - 407
GET /create_partner_trade_by_buyer 304 17ms
GET /images/new-btn-fixed.png 200 11ms - 5.76kb
GET /method=post?WIDout_trade_no=123&WIDsubject=11&WIDprice=1&WIDquantity=1&WIDlogistics_fee=1&WIDlogistics_type=EXPRESS&WIDlogistics_payment=SELLER_PAY&WIDbody=&WIDshow_url=&WIDreceive_name=&WIDreceive_address=&WIDreceive_zip=&WIDreceive_phone=&WIDreceive_mobile= 404 5ms
HEAD /method=post 404 2ms

下单的时候按理说是该POST的,但还是GET,请问是为什么呢?

顺便请问下,我希望通过http传递数据到后台后直接返回一个http地址然后打开就是支付宝付款的地址,请问应该如何实现呢?现在的方法都是要用到res的

支付回调证书错误

error:140DC009:SSL routines:SSL_CTX_use_certificate_chain_file:PEM lib 即时收款,回调报错了,请帮解答一下

支付回调验证失败

如果在subject里面放入中文,回调的时候会以乱码的形式存在,这个时候验证必定失败,java里面是params.put(name, new String (valueStr.getBytes("ISO-8859-1"),"UTF-8")),不知道node里面怎么处理

跳转到支付宝页面

跳转过程中会页面过程会出现一个确定按钮,最好在alipay_submit.class.js的buildRequestForm方法里的确认按钮加个隐藏style,即display: none。

several issues and fix diff file here

diff --git a/lib/alipay_core.function.js b/lib/alipay_core.function.js
index 848dc02..4ebff51 100644
--- a/lib/alipay_core.function.js
+++ b/lib/alipay_core.function.js
@@ -101,6 +101,7 @@ exports.logResult = function(word){

  • @param input_charset 编码格式。默认值:空值

  • return 远程输出的数据
    */

    • //TODO: cannot handle http request^M
      exports.getHttpResponsePOST = function(url, cacert_url, para, input_charset, ca
      input_charset = input_charset || '';
      if(input_charset.trim() != ''){
      diff --git a/lib/alipay_md5.function.js b/lib/alipay_md5.function.js
      index 454f44a..6a4bbb8 100644
      --- a/lib/alipay_md5.function.js
      +++ b/lib/alipay_md5.function.js
      @@ -41,7 +41,7 @@ exports.md5Sign = function(prestr, key){

    exports.md5Verify = function(prestr, sign, key){
    prestr = prestr + key;

    • var mysgin = crypto.createHash('md5').update(prestr).digest("hex");
    • var mysgin = crypto.createHash('md5').update(prestr, 'utf-8').digest("hex")

    if(mysgin == sign) {
    return true;
    @@ -49,4 +49,4 @@ exports.md5Verify = function(prestr, sign, key){
    else {
    return false;
    }
    -}
    +}^M
    diff --git a/lib/alipay_notify.class.js b/lib/alipay_notify.class.js
    index fbb4e40..dea9b56 100644
    --- a/lib/alipay_notify.class.js
    +++ b/lib/alipay_notify.class.js
    @@ -104,7 +104,7 @@ AlipayNotify.prototype.getSignVeryfy = function(para_temp, s
    var para_sort = core_funcs.argSort(para_filter);

    //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串

    • var prestr = createLinkstring(para_sort);
    • var prestr = core_funcs.createLinkstring(para_sort);^M

    var isSgin = false;

签名的时候prestr不应该用qs.stringify

因为它会把你的所有参数urlencode了,而支付宝要求hash之前的待签名字符串不能urlencode
另外,AlipaySubmit.prototype.buildRequestForm这个方法通过构建form表单,然后让浏览器提交的方式构造请求,这种做法相当奇葩,不知道作者有意为之,还是无耐之举,有意思,哈哈哈。

哦,另外,作者的代码里的局部变量前面都木有var 声明,这样会变成定义一个模块内的全局变量。不知道作者的用意何在。我觉得还是比较危险,建议修正。

总得来讲,东西还是挺简单易用的,谢谢。

Notify/Return runs ok,here's some comments

1.for initAlipayConfig,(partner,key,seller_email,host,transport,cacert,input_charset,sign_type) are needed.
2.cacert can be found in offical's PHP's demo,pay attention to path.
3.transport should be set as https
4.To use notify/return ,please append a line in alipay.js
exports.AlipayNotify =AlipayNotify;
so you could use
var AlipayNotify = require('alipay').AlipayNotify,
so that
alipayNotify.verifyNotify or alipayNotify.verifyReturn
is ok
5.one more thing,alipayNotify.verifyNotify use post,please use req.body to get post content

rsa加密的支持

支付宝官方的phpdemo中提供的是 rsa的加密方式,请问nodejs为啥用了md5的加密方式;支持rsa的加密的方式么?

服务器异步通知 query参数一直获取为空

我的代码是:

app.post('/user/alipay',userAlipay);//用户支付后,支付宝服务器会调用这个url。

var userAlipay = function(req,res){
    var query = req.query;
    console.log("hehw");
    console.log(query);
    res.send("success");
}

query 一直是空对象{},我给支付宝服务器回调的地址是个ip地址,这个有关系吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.