Class: UmfHttp
- Inherits:
-
Object
- Object
- UmfHttp
- Defined in:
- lib/UmfHttp.rb
Instance Method Summary collapse
-
#httpGet(urlStr) ⇒ Object
向服务端发起GET请求.
-
#httpPost(urlStr, params) ⇒ Object
向服务端发起POST请求.
-
#httpRequestWithJson(urlStr, isPost, jsonParam, headers) ⇒ Object
—————————————- 子商户入网部分 —————————————-.
- #parseHTMLStr(htmlStr) ⇒ Object
Instance Method Details
#httpGet(urlStr) ⇒ Object
向服务端发起GET请求
26 27 28 |
# File 'lib/UmfHttp.rb', line 26 def httpGet(urlStr) end |
#httpPost(urlStr, params) ⇒ Object
向服务端发起POST请求
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/UmfHttp.rb', line 32 def httpPost(urlStr, params) uri = URI.parse(urlStr) https = Net::HTTP.new(uri.host) https.use_ssl = false req = Net::HTTP::Post.new(uri.path) param = UmfStringUtil.new.rasEncryptedStrEscape(params) param = UmfStringUtil.new.getPlainSortByAnd(param) UmfLogger.logInfoMsg("[UMF SDK]本次请求 service = " + params["service"] + " 对应的请求体 request.body = " + param) req.body = param res = https.request(req) output = res.body #{res.code} #{res.message}: #{res.body} UmfLogger.logInfoMsg("[UMF SDK]本次请求原始响应数据 " + output.force_encoding("utf-8")) # 对账直接返回 if params["service"] == "download_settle_file" UmfLogger.logInfoMsg("[UMF SDK] 对账接口返回原始响应数据 " + output) return output end # 解析HTML返回 CONTENT contentStr = parseHTMLStr(output) contentArr = contentStr.split("&") response = {} contentArr.each { |elem| arr = elem.split("=",2) response[arr[0]] = arr[1] } UmfLogger.logInfoMsg("[UMF SDK]本次请求处理后返回的响应数据 " + response.to_s) UmfLogger.logInfoMsg("--------------------log end---------------------") response.delete('sign') response.delete('sign_type') response.delete('version') return response end |
#httpRequestWithJson(urlStr, isPost, jsonParam, headers) ⇒ Object
子商户入网部分
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/UmfHttp.rb', line 111 def httpRequestWithJson(urlStr,isPost,jsonParam,headers) UmfLogger.logInfoMsg("[UMF SDK 子商户入网]本次请求对应的URL " + urlStr) UmfLogger.logInfoMsg(isPost == true ? "[UMF SDK 子商户入网]本次请求方式 post" : "[UMF SDK 子商户入网]本次请求方式 get") # if(strpos($urlStr, UMF_RESTPAY_UPLOADCHILDFILE) !== false){ # //上传文件接口 由于文件的二进制数据过大 不写入log # }else{ # $log->logInfo("[UMF SDK 子商户入网]本次请求对应的json " .$jsonParam); # } uri = URI.parse(urlStr) https = Net::HTTP.new(uri.host) https.use_ssl = false if isPost==true req = Net::HTTP::Post.new(uri,headers) req.body = jsonParam res = https.request(req) response = res.body else isPost==false req = Net::HTTP::Get.new(uri,headers) res = https.request(req) response = res.body end # 验签 arr = response.split('&',2) if arr.length == 2 resPlain = arr[0] resSign = arr[1] verifyRet = UmfRSACryptUtil.new.verify(resPlain,resSign,'sha256') if verifyRet == true puts "[UMF SDK 子商户入网] 平台响应数据验证签名成功" UmfLogger.logInfoMsg("[UMF SDK 子商户入网]本次请求原始响应数据 " + response.force_encoding('utf-8').to_s) UmfLogger.logInfoMsg("--------------------log end---------------------") return JSON.parse(resPlain) else puts "[UMF SDK 子商户入网] 平台响应数据验证签名失败" end elsif urlStr==UMF_RESTPAY_AUTHORIZE return JSON.parse(response) end end |
#parseHTMLStr(htmlStr) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/UmfHttp.rb', line 67 def parseHTMLStr(htmlStr) if htmlStr.length <= 0 return end # MobilePayPlatform regex = /CONTENT="([\w\W]*?)"/ content = regex.match(htmlStr).to_s.split("=",2)[1] resParamsArr = content.split("&") plain = '' sign = '' resParamsArr.each { |elem| arr = elem.split("=",2) if arr[0]=="sign_type" next end if arr[0]=="sign" sign = arr[1] next end plain = plain + elem + "&" } plain = plain.chop plain = plain.delete '"' sign = sign.chop begin # plain utf8-->gbk plain = plain.encode('gbk','utf-8') rescue Encoding::UndefinedConversionError puts $!.error_char.dump p $!.error_char.encoding end verifyRet = UmfRSACryptUtil.new.verify(plain,sign,"sha1") if verifyRet puts "[UMF SDK] 平台响应数据验证签名成功" return content else puts "[UMF SDK] 平台响应数据验证签名失败" end end |