Last active
April 9, 2019 16:38
-
-
Save hardywu/1ec9790bceba0f0c3ba1bf667ed8ee0a to your computer and use it in GitHub Desktop.
chenpay ruby version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
require 'faraday' | |
require 'faraday_middleware' | |
class Job | |
# queue_as :default | |
attr_accessor :cookie | |
@cookie = false | |
def con | |
@con ||= Faraday.new do |f| | |
f.response :json | |
f.use :gzip | |
f.request :url_encoded | |
f.adapter :net_http | |
end | |
end | |
def headers | |
{ | |
'Cookie' => cookie, | |
'Accept-Encoding' => 'gzip, deflate, br', | |
'Accept-Language' => 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7', | |
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36', | |
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', | |
'Accept' => 'application/json, text/javascript', | |
'Origin' => 'https://mbillexprod.alipay.com', | |
'Connection' => 'keep-alive' | |
} | |
end | |
def refresh | |
con.post do |req| | |
req.url "https://enterpriseportal.alipay.com/portal/navload.json?t=#{Time.now.to_i * 1000}" | |
req.headers.merge! headers | |
req.headers['Referer'] = 'https://mbillexprod.alipay.com/enterprise/tradeListQuery.htm' | |
req.body = URI.encode_www_form(action: 'loadEntInfo') | |
end | |
end | |
def trades(from = Time.zone.today.prev_day, to = Time.zone.today) | |
con.post do |req| | |
req.url 'https://mbillexprod.alipay.com/enterprise/tradeListQuery.json' | |
req.headers.merge! headers | |
req.headers['Referer'] = 'https://mbillexprod.alipay.com/enterprise/tradeListQuery.htm' | |
req.body = URI.encode_www_form( | |
queryEntrance: 1, | |
billUserId: cookie[/uid=(\d*)/, 1], | |
status: 'SUCCESS', | |
entityFilterType: 0, | |
activeTargetSearchItem: 'tradeNo', | |
tradeFrom: 'ALL', | |
startTime: from.strftime('%Y-%m-%d 00:00:00'), | |
endTime: to.strftime('%Y-%m-%d 23:59:59'), | |
pageSize: 20, | |
pageNum: 1, | |
total: 1, | |
sortTarget: 'gmtCreate', | |
order: 'descend', | |
sortType: 0, | |
_input_charset: 'gbk', | |
ctoken: cookie[/ctoken=([^\;]+)/, 1] | |
) | |
end | |
end | |
def funds(from = Time.zone.today.prev_day, to = Time.zone.today) | |
con.post do |req| | |
req.url 'https://mbillexprod.alipay.com/enterprise/fundAccountDetail.json' | |
req.headers.merge! headers | |
req.headers['Referer'] = 'https://mbillexprod.alipay.com/enterprise/fundAccountDetail.htm' | |
req.headers['X-Requested-With'] = 'XMLHttpRequest' | |
req.body = URI.encode_www_form( | |
queryEntrance: 1, | |
billUserId: cookie[/uid=(\d*)/, 1], | |
showType: 1, | |
type: '', | |
precisionQueryKey: 'tradeNo', | |
startDateInput: from.strftime('%Y-%m-%d 00:00:00'), | |
endDateInput: to.strftime('%Y-%m-%d 23:59:59'), | |
pageSize: 20, | |
pageNum: 1, | |
total: 0, | |
sortTarget: 'tradeTime', | |
order: 'descend', | |
sortType: 0, | |
_input_charset: 'gbk', | |
ctoken: cookie[/ctoken=([^\;]+)/, 1] | |
) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment