chloerei / alipay Goto Github PK
View Code? Open in Web Editor NEWUnofficial alipay ruby gem
License: MIT License
Unofficial alipay ruby gem
License: MIT License
目前有需求向外国人出售软件产品。经过调查认为支付宝只支持人民币。 我看到这个gem的文档,提到境外收单。想了解下支付宝是可以实现美元收款的吗?还有是否支持国外的visa,master card等等支付方式?
问题可能跟技术无关哈。 如果有一个运行中的例子就最好了,一看便知。
sdk_execute方法返回的就是APP SDK请求的参数.
示例中的method应该修改为: 'alipay.trade.app.pay'
# Generate a query string that use for APP SDK excute.
#
# Example:
#
# alipay_client.sdk_execute(
# method: 'alipay.trade.page.pay',
# biz_content: {
# out_trade_no: '20160401000000',
# product_code: 'QUICK_MSECURITY_PAY',
# total_amount: '0.01',
# subject: 'test'
# }.to_json,
# timestamp: '2016-04-01 00:00:00'
# )
# # => 'app_id=2016000000000000&charset=utf-8&sig....'
def sdk_execute(params)
params = prepare_params(params)
URI.encode_www_form(params)
end
`
@alipay_client.page_execute_url(
method: AlipayScan::Interface::TradePagePay,
biz_content: JSON.generate({
out_trade_no: '1234567891112',
product_code: 'FAST_INSTANT_TRADE_PAY',
total_amount: '0.01',
subject: '测试一下',
qr_pay_mode: 4,
}, ascii_only: true),
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
notify_url: "#{::HostSetting.domain}/pay/alipays/alipay_scan_code_notify",
)`
扫码支付成功后 不通知notify_url的地址,请问支持notify_url参数吗。
如题: 我在使用alipay.trade.app.pay 时, 传过 app_id依旧,返回错误提示 “缺少app_id”, 。 请问这个gem支付app支付吗
回调中报错:ActionController::BadRequest (Invalid request parameters: Invalid encoding for parameter: ���Ų����ײ�)。
试着加入中间件拦截后发现回调中的 charset 是 GBK。可能是我的 subject 参数是中文的原因
目前解决方案是在网关地址后面加 ?charset=UTF-8
@client = Alipay::Client.new(
url: "https://openapi.alipay.com/gateway.do?charset=UTF-8",
app_id: APP_ID,
app_private_key: APP_PRIVATE_KEY,
alipay_public_key: ALIPAY_PUBLIC_KEY
)
不知不觉,从 alipay v0.0.1 发布至今已经过去一年半了。一开始这个 gem 只有担保交易和确认发货两个接口,在多人的贡献下,alipay 支持越来越多的接口。
逐渐这个项目有点难维护了:
所以我在 0.6.0.beta1 进行了一些改进:
项目地址: https://github.com/chloerei/alipay-demo
这个是个 Rails app,它有两个目的,一是演示 alipay gem 的用法,二是供 gem 的开发者测试。它为 heroku 部署做了优化,可以免费部署到 heroku 做在线调试。你可以查看项目的 README,或者 Heroku 的文档了解如何部署 Rails app https://devcenter.heroku.com/articles/getting-started-with-rails4 。
目前它只有担保交易和确认发货的示例,因为我只有这两个接口的访问权限。欢迎其它接口的贡献者也为这个项目添加接口的示例,这样以后调试的时候就不用部署测试环境的生产应用了(当然最终更新 gem 到生产环境前还是应该先用真实应用测试)。
贡献示例请按照以下准则:
提交按照一般的 PR 流程既可。友情提示:当在调试 alipay gem 的时候,可以创建一个 alipay-demo 分支,更新 Gemfile 指向自己的的 alipay branch 用作测试。
我计划中为了发布 0.6.0 还需要完成:
希望 alipay gem 的贡献者和使用者提供反馈,集成支付宝的过程很痛苦,一个良好维护的 gem 能让痛苦来得轻一点。
调用 alipay.trade.precreate 时,如果 subject 含有中文,用支付宝 APP 扫描二维码,商品名称会显示成乱码,设置 charset 、转换编码都没用。
alipay_client = Alipay::Client.new(
url: 'https://openapi.alipaydev.com/gateway.do',
app_id: '2016000000000000',
app_private_key: APP_PRIVATE_KEY,
alipay_public_key: ALIPAY_PUBLIC_KEY
)
alipay_client.page_execute_url(
method: 'alipay.trade.page.pay',
biz_content: {
out_trade_no: '20160401000000',
product_code: 'FAST_INSTANT_TRADE_PAY',
total_amount: '0.01',
subject: 'test'
}.to_json, # to_json is important!
timestamp: '2016-04-01 00:00:00'
)
# => 'https://openapi.alipaydev.com/gateway.do?app_id=201600...'
经过几次调试后,我将上述 README 中 to_json 位置的代码改为 JSON.generate(biz_content, ascii_only: true) 后,终于显示正常。建议更新 README 和相关代码。
irb(main):001:0> { subject: '测试' }.to_json
=> "{\"subject\":\"测试\"}"
irb(main):002:0> JSON.generate({ subject: '测试' }, ascii_only: true)
=> "{\"subject\":\"\\u6d4b\\u8bd5\"}"
Hi Rei,
可能你还记得,我录制过一本支付宝站内集成的课程:http://haoqicat.com/happypeter/zhi-fu-bao-shou-kuan-ji-cheng 一年来卖了30来个拷贝。我觉得挺高兴,不过最近我这套课程需要更新了,因为支付宝下线了“双功能”接口,而我的课程中是以双功能为核心来讲的。用的 Gem 是我参考你和大庆的项目自己拼凑的 alipay_dualfun 。
最近的改进版中,我打算完全按照你的这个 Gem 来讲,我会
不知道大牛你意下如何?
use alipay.trade.pay interface. if I am use subject chinese, interface is error: "Invalid Arguments". else if I am use subject en, then successfully.
支付宝网银支付的功能有集成吗?
新支付网关 https://openapi.alipay.com/gateway.do
下API支持
在支付参数中加入 app_pay: 'Y', 如手机已安装支付宝客户端,浏览器会提示是否呼出客户端支付。
亲测 create_forex_trade_wap 有效,可否在文档添加此处说明,毕竟 native支付要比网页支付体验好的多
我在尝试将过去为alipay打的补丁合并到最新的开发版本当中,其中实现了
结合支付宝的API文档和通过浏览最近版本的代码,有一点想讨论:
以平台的方式组织文件,而不是用途,是不是更好一些?简单的说就是wap
目录中存放sign.rb
, notify.rb
, service.rb
,这样属于wap平台的API和相关函数在同一命名空间下,同理App平台的相关函数。
签名算法放入sign
目录,即Sign
命名空间,然后不同的算法单独文件保存,如 Alipay::Sign::Md5
且只包含 generate
和verify?
两个方法,因为不同平台的API的params_to_string
的算法有可能是不同的,就交给不同平台的sign.rb
去处理
我认为这样处理的话会更清晰,而且容易修改,看看大伙有什么看法,我来考虑如何移植代码
按照官方的教程 上传了RSA1024 跟 RSA2 2048的公钥
拿到了各自的支付宝支付宝公钥
结果也是字符串写到配置
F, [2018-07-20T17:01:13.906460 #28170] FATAL -- : [3ded77cb-d40d-4c25-b6fd-df1893b03b12]
F, [2018-07-20T17:01:13.906676 #28170] FATAL -- : [3ded77cb-d40d-4c25-b6fd-df1893b03b12] OpenSSL::PKey::RSAError (Neither PUB key nor PRIV key: nested asn1 error):
F, [2018-07-20T17:01:13.906813 #28170] FATAL -- : [3ded77cb-d40d-4c25-b6fd-df1893b03b12]
请问有没有遇到一样情况的同学
手机网站支付alipay sdk文档的服务名称是alipay.wap.create.direct.pay.by.user.
谢谢~~
计划做个优化,升级到最新api,同时也具备兼容老版本的能力。
更新readme,按支付宝收款产品分类(电脑网站支付,手机网站支付),与支付宝官方文档的名字对应起来,同时标注支付宝官方的状态(部分接口官方可能不再支持)。
readme增加目录;
新版本手机支付api(https://doc.open.alipay.com/docs/doc.htm?treeId=203&articleId=105285&docType=1)
Someone wrote a wrapper of alipay for spree based on alipay 0.10.0
(github.com/formrausch/spree_alipay_forex_trade).
I want to modify this wrapper to support alipay 0.15.1, Can you give me some suggest ?
朋友,支付宝移动网站支付要用RSA,我看了你写的这部分获取sign的代码,用这个生成的sign还是无法发起支付宝支付
def self.sign(key, string)
sa = OpenSSL::PKey::RSA.new(key)
Base64.encode64(rsa.sign('sha1', string))
end
RT,在我们的系统里,浏览器里的一般调用使用了MD5方式签名,但APP必须使用RSA方式签名,是不是分成md5_key
和rsa_key
更合适?
(最近工作比较紧,先提一下建议看看意见)
lib/alipay/mobile/service.rb line 5 mobile_securitypay_pay_string
readme mobile_security_pay_string
我的理解是移动支付需要RSA sign_type。需要自己生成private key 和 public key. public key需要上传给支付宝网站,private key怎么提供给request呢?可能我的理解有误,希望可以简单介绍一下怎么在这个gem里设置和使用RSA这个sign type。
使用wap支付接口出现
NoMethodError (undefined method `auth_and_execute' for Alipay::Wap::Service:Module):
版本:0.7.1
rails 4.2
For the create_direct_pay_by_user_url
method, when the message contains unicode such as :subject => "珊瑚+x+1,"
, later notification verification will fail. The sign doesn't match with the one returned by Alipay.
Hi @chloerei, sorry for adding an issue when it is not necessarily one, I am just curious as it seems that, once the customer goes through the checkout process on Alipay, there is no redirection to the origin website (as would be the case with Paypal).
I'm not fluent in Chinese and I would like to see if you can confirm that behavior?
What I'd like is for Alipay to redirect to our merchant site once the direct pay transaction is completed but that's not what is happening even though I specified the return_url in the options...
Thanks for your help!
开发者文档中说明,seller_email 和 seller_id 两者填一个即可。email 并非必填参数,而且有的账户并没有 email。如果我在Rails起始时候不载入 Alipay.seller_email
的话,这个 gem 仍然会试图在参数中加入 &seller_email=''
。空参数会在阿里侧造成签名错误,也就是 ILLEGAL_SIGN
错误。希望如果使用者没有给 Alipay.seller_email
赋值的话,在发出请求时不要包括它。
错误提示是这个
使用下面的方式调用
参考的是https://github.com/chloerei/alipay-demo
I found that alipay sand box should go 'https://openapi.alipaydev.com/gateway.do?'
and live is 'https://mapi.alipay.com/gateway.do?'
I tried to update the test url.
However, I don't know how to generate the API info.
Can I ask how can you get the API partner, key and signature for alipay sandobx?
(I created a sandbox acct but seems not able to generate the API key
https://sandbox.alipaydev.com)
我发现文档要求的请求参数和签名返回的参数有些不一致, 能帮忙检查一下吗?
我看文档中,这个gem并没有提供“确认收货”的接口,后面想着可以自己实现,然后提交到gem中,后面找了一遍文档也没有发现对应的接口。
难道说“担保交易”真的没有提供这样的接口?如果不走到支付宝页面手动点击“确认收货”的话,就只能等待自动结算了?
hi @chloerei ,支付宝官方的 pdf 和你的 README 中,下面的接口都只需要两个参数就行了
Alipay::Service.send_goods_confirm_by_platform(
trade_no: '201504010000001',
logistics_name: 'example.com'
)
但是我实际测了一下,必须要加上 :transport_type => 'DIRECT'
才可以成功。
我觉得是支付宝那边的一个 bug ,你觉得呢?
返回的参数验证失败,不知道大家的都正常吗?
Hi Rei,
前面跟你沟通过的,我的支付宝收款集成课程:http://haoqicat.com/happypeter/zhi-fu-bao-shou-kuan-ji-cheng 已经更新完毕。新版中全部代码都是围绕你的 alipay gem ,感谢你的劳动。
如果方便的话,请把课程链接加到本项目的某个地方,方便大家找到。另外,欢迎你对课程提出意见,我会继续改进的。谢谢!
在设置担保交易接口参数时,logistics_type 能设置为DIRECT吗?
irb> client = Alipay::Client.new(url: url,app_id: app_id,app_private_key: app_private_key,sign_type: 'RSA')
irb> client.execute(method: 'alipay.fund.trans.toaccount.transfer',biz_content: biz_content.to_json)
=> "{\"code\"=>\"40002\", \"msg\"=>\"Invalid Arguments\", \"sub_code\"=>\"isv.invalid-app-id\", \"sub_msg\"=>\"\\xCE\\xDE\x{D0A7}\\xB5\\xC4AppID\\xB2\\xCE\\xCA\\xFD\"}"
返回的sub_msg
这里应该是中文的字符串
有时会需要使用多个帐号,例如更换商户帐号的时候,新订单支付地址使用新帐号,旧的订单在一段时间内还需要处理异步消息。
方案一:
在现有方法上扩展,每个方法可以传入参数从而使用不同的帐号。
Alipay.pid = 'acount_1'
Alipay.seller_email = 'seller_email_1'
Alipay.key = 'key_1'
Alipay::Service.create_partner_trade_by_buyer_url(out_trade_no: 1000) # 使用 account_1
Alipay::Service.create_partner_trade_by_buyer_url(
out_trade_no: 1000,
pid: 'account_2',
seller_email: 'seller_email_2,
key: 'key_2'
) # 使用 account_2
如果要使用很多商户帐号,那么不设置默认值也可以。这个方案类似于 Stripe 的接口 https://stripe.com/docs/api/ruby
这个方案优势是改动小,api 基本不变,但是代码隔离不清晰。
方案二:
更改所有接口,需要先实例化:
alipay_1 = Alipay::Service.new(
pid: 'acount_1',
key: 'key_1'
)
alipay_2 = Alipay::Service.new(
pid: 'acount_2',
key: 'key_2'
)
alipay_1.create_partner_trade_by_buyer_url(..) # 使用 account_1
alipay_2.create_partner_trade_by_buyer_url(..) # 使用 account_2
这种方式类似于 dalli, redis-rb。
这个方案优势是代码隔离清晰,对象化,缺点是 api 全部要变更。
哪个方案比较好?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.