AuthProxy.lua 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local AuthProxy = class("AuthProxy", RemoteProxy)
  3. AuthProxy.NAME = global.ProxyTable.AuthProxy
  4. local sha1 = require( "sha1/init" )
  5. local cjson = require("cjson")
  6. local socket = require "socket"
  7. local sformat = string.format
  8. local appid = "10001"
  9. local gameid = "1"
  10. local signkey = "634eff98723b31da43ed35f0dd4edf36" --key"dc772af6372cea474ceb38ea5acc9104"
  11. local doamin = "http://sdk.dhsf.xqhuyu.com/"
  12. local url_visitor = "user/yk_register" -- 地址: 游客登录
  13. local url_forgetpwd = "user/forgetPassword" -- 地址: 忘记密码
  14. -- local url_bindPhone = "user/bindPhone" -- 地址: 绑定手机
  15. local url_alipay = "pay/alipay" -- 地址: 支付宝支付
  16. local url_weixin = "pay/wap_wx" -- 地址: 微信支付
  17. local url_alipay_sdk = "PayQuyou/wap_alipay" -- 地址: 三方支付宝
  18. local url_weixin_sdk = "PayQuyou/wap_wx" -- 地址: 三方微信
  19. local url_qrcode_alipay_sdk = "PayQuyou/qrcode_alipay" -- 地址: 三方支付宝 二维码
  20. local url_qrcode_weixin_sdk = "PayQuyou/qrcode_wx" -- 地址: 三方微信 二维码
  21. -- local url_decode_jwt = "XlNotify.php" -- 地址: 解密jwt HS256
  22. -- 现在支付
  23. local xz_url_pay = "PayX/xzH5Pay"
  24. local xz_qrcode_pay = "PayX/xzCodePay"
  25. local xz_get_qrcode = "PayX/getUserQrcode"
  26. local newDoamin2= "http://pay-sdkv2.dhsf.xqhuyu.com/api/"
  27. local url_qrcode_weixin = "pay/orderPlace" -- 地址: 二维码支付 微信 以前的doamin .. "pay/qrcode_wx"
  28. local url_qrcode_alipay = "pay/orderPlace" -- 地址: 二维码支付 支付宝 以前的doamin .. "pay/qrcode_alipay"
  29. local url_get_qrcode = "pay/getUserQrcode" -- 地址: 下载二维码 以前的doamin .. "pay/get_user_qrcode"
  30. -- 聚合
  31. local juhe_secret_key = "ptONCD6UxNbQRxYrvdVpFACgL1Ir53rjfUO0lOM2Did0ZxGEg2WB0WfhtsqTT2ee"
  32. local juhe_domain = "http://pcjuhe.dhsf.xqhuyu.com"
  33. local juhe_url_pay = "/v1/recharge"
  34. local juhe_url_upload = "/v1/yylog"
  35. local domain_qqGame = "https://xdwqq.dhsf.xqhuyu.com"
  36. local juhe_url_qqPay = "/v1/qq_buy"
  37. local juhe_url_qqUpload = "/v1/qq_yylog"
  38. local juhe_url_qqFilter = "/v1/uic_filter"
  39. local doamin2 = "http://sdkv2.dhsf.xqhuyu.com/api/" -- 测试:"http://sdk-dev.dhsf.xqhuyu.com/api/"
  40. local url_authCode = "user/sendsms" -- 地址: 发送手机验证码
  41. local url_register = "user/reg" -- 地址: 普通注册
  42. local url_login = "user/login" -- 地址: 登录
  43. local url_bindPhoneByMb = "user/bindPhoneByMb" -- 地址: 绑定手机 密保绑定
  44. local url_changePhone = "user/changePhone" -- 地址: 修改手机
  45. local url_changepwdByPhone = "user/changePwdByPhone" -- 地址: 修改密码 验证码修改
  46. local url_changepwdByMb = "user/changePwdByMb" -- 地址: 修改密码 密保修改
  47. local url_changeMb = "user/changemb" -- 地址: 修改密保
  48. local url_checkToken = "user/checkToken" -- 地址: 检测token有效性
  49. local url_identify = "user/identification" -- 地址: 实名认证
  50. local url_loginByPhone = "user/phoneLogin" -- 地址: 手机验证码登录
  51. -- 盒子创角上报
  52. local domain_box = "https://user-api.996box.com" -- 测试:"boxuser-dev.dhsf.xqhuyu.com"
  53. local url_roleAD = "/v1/AdData/pcGameRole"
  54. local signBoxKey = "zg1zn559tgh4enh25mz2hn2" -- 盒子秘钥
  55. -- 新游推荐上报创角
  56. local domain_boxN = "http://footprint.996box.com" -- 测试: "http://anvj.dhsftest.xqhuyu.com"
  57. local url_roleNewRecom = "/api/GameRecommend/pcGameRole"
  58. -- PC盒子支付拉取场景
  59. local url_getSceneInfo = "/api/GameRole/getSceneInfo"
  60. local boxSceneSignKey = "7PZJImoeAE5Dnjb6pCYu8Ja5Buhb2urL"
  61. -- 腾讯域名
  62. local host_tencent = "https://openapi.minigame.qq.com" --"http://openapi.tencentyun.com" -- test "http://openapi.sparta.html5.qq.com/"
  63. --云手机上报
  64. local cloud_money_url = "https://game-api.996hezi.com"
  65. local cloud_box_url = "https://api.996box.com"
  66. local cloud_record_url = "/cloud/v1/device/recordGameUser"
  67. local cloud_money_list_url = "/cloud-game/v1/engine/hang/status"
  68. local cloud_otherlogin = "/cloud/v1/engine/account/conflict"
  69. local cloud_check_money_list= "/cloud/v1/engine/currency/config"
  70. --检测modeInfoURL合法性
  71. local mode_info_check = "https://user-sdkv2.dhsf.xqhuyu.com" -- "https://user-sdkv2.dhsf.xqhuyu.com" --pre "https://user-sdkv2-pre.dhsf.xqhuyu.com" --test "https://user-sdkv2-test.ppp996.hqyxkj.cn"
  72. local mode_info_interface = "/api/user/checkHost"
  73. -- vip上报
  74. local vip_domain = ""
  75. local vip_upload_url = "/gameserver_api/game_platform/notice_vip"
  76. AuthProxy.PAY_CHANNEL =
  77. {
  78. ALIPAY = "ALIPAY", -- 支付宝
  79. HUABEI = "HUABEI", -- 花呗
  80. WEIXIN = "WEIXIN", -- 微信
  81. }
  82. AuthProxy.PAY_TYPE =
  83. {
  84. NATIVE = "NATIVE", -- 原生
  85. QRCODE = "QRCODE", -- 二维码
  86. }
  87. local function urlencodechar(char)
  88. return "%" .. string.format("%02X", string.byte(char))
  89. end
  90. local function urlencodeT(input)
  91. -- convert line endings
  92. input = string.gsub(tostring(input), "\n", "\r\n")
  93. -- escape all characters but alphanumeric, '.' and '-'
  94. input = string.gsub(input, "([^%w%.%-%_%~ ])", urlencodechar)
  95. -- convert spaces to "+" symbols
  96. return string.gsub(input, " ", "+")
  97. end
  98. local function calcSuffix(originData)
  99. -- ascii排序
  100. table.sort(originData, function(a, b)
  101. return a.key < b.key
  102. end)
  103. -- 计算sign
  104. local origin = ""
  105. local realOrigin = ""
  106. for i, v in ipairs(originData) do
  107. local send_value = v.value
  108. if send_value then
  109. if string.find(send_value, "%%") then
  110. local strList = string.split(send_value, "%")
  111. local t = urlencodeT("%")
  112. send_value = table.concat(strList, t)
  113. end
  114. if string.find(send_value, "%+") then
  115. local strList = string.split(send_value, "+")
  116. local t = urlencodeT("+")
  117. send_value = table.concat(strList, t)
  118. end
  119. if string.find(send_value, "%&") then
  120. local strList = string.split(send_value, "&")
  121. local t = urlencodeT("&")
  122. send_value = table.concat(strList, t)
  123. end
  124. end
  125. origin = origin .. sformat("%s=%s", v.key, v.value)
  126. origin = origin .. (i < #originData and "&" or "")
  127. realOrigin = realOrigin .. sformat("%s=%s", v.key, send_value)
  128. realOrigin = realOrigin .. (i < #originData and "&" or "")
  129. end
  130. local sign = sha1.hmac(signkey, origin)
  131. -- 拼接sign
  132. local suffix = realOrigin .. "&" .. sformat("sign=%s", sign)
  133. return suffix
  134. end
  135. local function getHeader()
  136. local header = {
  137. imei = "",
  138. imei2 = "",
  139. meid = "",
  140. deviceid = "",
  141. }
  142. return header
  143. end
  144. local function calcBoxSignSuffix(originData, secret_key, unlencode)
  145. table.sort(originData, function(a, b)
  146. return a.key < b.key
  147. end)
  148. -- 拼接
  149. local origin = ""
  150. local valueStr = ""
  151. for i, v in ipairs(originData) do
  152. if v and v.key and v.value and string.len(v.key) > 0 and string.len(v.value) > 0 then
  153. if unlencode then
  154. origin = origin .. string.format("%s=%s", v.key, urlencodeT(v.value))
  155. else
  156. origin = origin .. string.format("%s=%s", v.key, v.value)
  157. end
  158. origin = origin .. "&"
  159. valueStr = valueStr .. v.value
  160. end
  161. end
  162. origin = string.sub(origin, 1, string.len(origin)-1)
  163. local rqtime = os.time()
  164. local rqrandom = randDataID("Box")
  165. valueStr = valueStr .. secret_key .. rqtime .. rqrandom
  166. origin = origin.."&rqtime="..rqtime.."&rqrandom="..rqrandom
  167. print("calcBoxSignSuffix", origin)
  168. --
  169. local signMD5 = get_str_MD5(valueStr)
  170. local suffix = origin .. "&" .. string.format("sign=%s", signMD5)
  171. return suffix
  172. end
  173. function AuthProxy:ctor()
  174. AuthProxy.super.ctor(self)
  175. ---------------------域名切换---------------------
  176. local BaseDoamin = self:GetCustomDataByKey("BaseDoamin")
  177. if BaseDoamin and string.len(BaseDoamin) > 0 then
  178. doamin = BaseDoamin .. "/"
  179. end
  180. local QRCodePayDoamin = self:GetCustomDataByKey("QRCodePayDoamin")
  181. if QRCodePayDoamin and string.len(QRCodePayDoamin) > 0 then
  182. newDoamin2 = QRCodePayDoamin .. "/api/"
  183. end
  184. local PCJuHeDoamin = self:GetCustomDataByKey("PCJuHeDoamin")
  185. if PCJuHeDoamin and string.len(PCJuHeDoamin) > 0 then
  186. juhe_domain = PCJuHeDoamin
  187. end
  188. local QQPayAndSensitiveWordDoamin = self:GetCustomDataByKey("QQPayAndSensitiveWordDoamin")
  189. if QQPayAndSensitiveWordDoamin and string.len(QQPayAndSensitiveWordDoamin) > 0 then
  190. domain_qqGame = QQPayAndSensitiveWordDoamin
  191. end
  192. local NewBaseDoamin = self:GetCustomDataByKey("NewBaseDoamin")
  193. if NewBaseDoamin and string.len(NewBaseDoamin) > 0 then
  194. doamin2 = NewBaseDoamin .. "/api/"
  195. end
  196. local BoxNDoamin = self:GetCustomDataByKey("BoxNDoamin")
  197. if BoxNDoamin and string.len(BoxNDoamin) > 0 then
  198. domain_boxN = BoxNDoamin
  199. end
  200. local TencentDoamin = self:GetCustomDataByKey("TencentDoamin")
  201. if TencentDoamin and string.len(TencentDoamin) > 0 then
  202. host_tencent = TencentDoamin
  203. end
  204. local BoxCloudDoamin = self:GetCustomDataByKey("BoxCloudDoamin")
  205. if BoxCloudDoamin and string.len(BoxCloudDoamin) > 0 then
  206. cloud_box_url = BoxCloudDoamin
  207. end
  208. local BoxDoamin = self:GetCustomDataByKey("996BoxDoamin")
  209. if BoxDoamin and string.len(BoxDoamin) > 0 then
  210. domain_box = BoxDoamin
  211. end
  212. local ModeInfoCheckDoamin = self:GetCustomDataByKey("ModeInfoCheckDoamin")
  213. if ModeInfoCheckDoamin and string.len(ModeInfoCheckDoamin) > 0 then
  214. mode_info_check = ModeInfoCheckDoamin
  215. end
  216. local cloudMoneyURL = self:GetCustomDataByKey("cloudMoneyURL")
  217. if cloudMoneyURL and string.len(cloudMoneyURL) > 0 then
  218. cloud_money_url = cloudMoneyURL
  219. end
  220. local hthostDomain = self:GetCustomDataByKey("hthost")
  221. if hthostDomain and string.len(hthostDomain) > 0 then
  222. release_print("leidianurl ".. hthostDomain)
  223. vip_domain = hthostDomain
  224. end
  225. -----------------------------------------------
  226. self._authCode = "" -- 手机短信授权码
  227. self._username = ""
  228. self._password = ""
  229. self._mobile = ""
  230. self._token = ""
  231. self._uid = ""
  232. local envProxy = global.Facade:retrieveProxy( global.ProxyTable.GameEnvironment )
  233. self._isSDKPay = tonumber(envProxy:GetCustomDataByKey("sdkPay")) == 1
  234. self._isXZPay = tonumber(envProxy:GetCustomDataByKey("XZPay")) == 1
  235. -- 临时处理,初始化一些必要参数
  236. local tmp = global.L_GameEnvManager:GetChannelID()
  237. if tmp and string.len(tmp) > 0 then
  238. appid = tmp
  239. end
  240. local currModule = global.L_ModuleManager:GetCurrentModule()
  241. local tmp = currModule:GetOperID()
  242. if tmp and string.len(tmp) > 0 then
  243. gameid = tmp
  244. end
  245. local tmp = global.L_GameEnvManager:GetSignkey()
  246. if tmp and string.len(tmp) > 0 then
  247. signkey = tmp
  248. else
  249. releasePrint("can't find signkey by env.json, use default")
  250. -- 测试用
  251. if global.isWindows and global.isDebugMode then
  252. global.L_GameEnvManager:SetChannelID("1")
  253. end
  254. end
  255. --
  256. self._orderId = ""
  257. -- 聚合SDK支付参数
  258. self._juhe_param_subject = global.L_GameEnvManager:GetEnvDataByKey("juhe_subject")
  259. self._juhe_param_game_id = global.L_GameEnvManager:GetEnvDataByKey("juhe_game_id")
  260. self._juhe_param_game_name = global.L_GameEnvManager:GetEnvDataByKey("juhe_game_name")
  261. self._juhe_param_agent_id = global.L_GameEnvManager:GetEnvDataByKey("juhe_agent_id") --渠道id [仅千贝]
  262. self._juhe_small_id = global.L_GameEnvManager:GetEnvDataByKey("juhe_small_id") --小号id [顺玩]
  263. self._juhe_origin_id = global.L_GameEnvManager:GetEnvDataByKey("original_user_id") --神游原始玩家id
  264. self._juhe_yx_extend = global.L_GameEnvManager:GetEnvDataByKey("yx_extend") -- 上报/支付 额外数据
  265. self.downloader = httpDownloader:new()
  266. self._canRenewal = false -- 可续期状态
  267. self:OnRegisterNativeFunc()
  268. end
  269. function AuthProxy:GetCustomDataByKey(key)
  270. local currentModule = global.L_ModuleManager:GetCurrentModule()
  271. local moduleGameEnv = currentModule:GetGameEnv()
  272. local customData = moduleGameEnv:GetCustomData()
  273. if not customData then
  274. return nil
  275. end
  276. return customData[key]
  277. end
  278. function AuthProxy:releaseDownloader()
  279. if httpDownloader.Destory and self.downloader then
  280. httpDownloader:Destory(self.downloader)
  281. self.downloader = nil
  282. end
  283. end
  284. function AuthProxy:resetDownloader()
  285. self:releaseDownloader()
  286. self.downloader = httpDownloader:new()
  287. end
  288. function AuthProxy:Cleanup()
  289. self._authCode = ""
  290. self._username = ""
  291. self._password = ""
  292. self._mobile = ""
  293. self._token = ""
  294. self._uid = ""
  295. end
  296. function AuthProxy:getGameId()
  297. return gameid
  298. end
  299. function AuthProxy:RequestLoginAdmin(data)
  300. self._username = data.username
  301. self._password = data.password
  302. self._uid = data.username
  303. self._token = data.password
  304. global.Facade:sendNotification(global.NoticeTable.AuthLoginSuccess, data)
  305. end
  306. function AuthProxy:SetData(data)
  307. self._username = data.uid
  308. self._password = data.token
  309. self._uid = data.uid
  310. self._token = data.token
  311. end
  312. function AuthProxy:OnRegisterNativeFunc()
  313. local function OnPcSdkLoginSuccess(sender, jsonString)
  314. local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
  315. local jsonData = jsonString and cjson.decode(jsonString)
  316. if jsonData and next(jsonData) then
  317. AuthProxy:SetData(jsonData)
  318. global.Facade:sendNotification(global.NoticeTable.AuthLoginSuccess, jsonData)
  319. end
  320. end
  321. -- register native status changing callback
  322. global.NativeBridgeCtl:removeSelectorsInGroup("PCLoginSuccess")
  323. global.NativeBridgeCtl:addNativeSelector("PCLoginSuccess", "NG_PcSdkLoginSuccess", OnPcSdkLoginSuccess, nil)
  324. end
  325. function AuthProxy:ReadLocalData()
  326. local userData = UserData:new("auth")
  327. self._username = userData:getStringForKey("username", "")
  328. self._password = userData:getStringForKey("password", "")
  329. self._token = userData:getStringForKey("token", "")
  330. self._uid = userData:getStringForKey("uid", "")
  331. self:ReadLocalCache()
  332. self:CleanLocalCache()
  333. end
  334. function AuthProxy:SaveLocalData()
  335. local savePassword = (global.isDebugMode or global.isGMMode) and self._password or ""
  336. local userData = UserData:new("auth")
  337. userData:setStringForKey("username", self._username)
  338. userData:setStringForKey("password", savePassword)
  339. userData:setStringForKey("token", self._token)
  340. userData:setStringForKey("uid", self._uid)
  341. userData:writeMapDataToFile()
  342. end
  343. function AuthProxy:ReadLocalCache()
  344. if global.isDebugMode then
  345. local userData = UserData:new("auth")
  346. local usernameCache = userData:getStringForKey("username_cache", "")
  347. local passwordCache = userData:getStringForKey("password_cache", "")
  348. if usernameCache ~= "" and passwordCache ~= "" then
  349. self._username = usernameCache
  350. self._password = passwordCache
  351. end
  352. end
  353. end
  354. function AuthProxy:SaveLocalCache()
  355. if global.isDebugMode then
  356. local savePassword = (global.isDebugMode or global.isGMMode) and self._password or ""
  357. local userData = UserData:new("auth")
  358. userData:setStringForKey("username_cache", self._username)
  359. userData:setStringForKey("password_cache", savePassword)
  360. userData:writeMapDataToFile()
  361. end
  362. end
  363. function AuthProxy:CleanLocalCache()
  364. local userData = UserData:new("auth")
  365. userData:setStringForKey("username_cache", "")
  366. userData:setStringForKey("password_cache", "")
  367. userData:writeMapDataToFile()
  368. end
  369. function AuthProxy:GetUsername()
  370. return self._username
  371. end
  372. function AuthProxy:GetPassword()
  373. return self._password
  374. end
  375. function AuthProxy:GetToken()
  376. return self._token
  377. end
  378. function AuthProxy:IsValidToken()
  379. return self._token and string.len(self._token) > 0
  380. end
  381. function AuthProxy:GetMobile()
  382. return self._mobile
  383. end
  384. function AuthProxy:GetUID()
  385. return self._uid
  386. end
  387. function AuthProxy:IsSDKPay()
  388. return self._isSDKPay
  389. end
  390. function AuthProxy:getOrderID()
  391. return self._orderId
  392. end
  393. --
  394. function AuthProxy:RequestAuthCode(phonenumber)
  395. -- 1、发送手机验证码
  396. local url = doamin2 .. url_authCode
  397. if not (url and string.len(url) > 0) then
  398. return false
  399. end
  400. -- http数据请求回调
  401. local function httpCB(success, response)
  402. if not success then
  403. ShowSystemTips("[-1] 获取验证码失败, 请求失败")
  404. return false
  405. end
  406. local jsonData = cjson.decode(response)
  407. if not jsonData then
  408. ShowSystemTips("[-2] 获取验证码失败, 解析失败")
  409. return false
  410. end
  411. if not (jsonData.code == 200) then
  412. ShowSystemTips("[-3] 获取验证码失败, 状态异常 " .. jsonData.msg)
  413. return false
  414. end
  415. dump(jsonData)
  416. end
  417. -- local suffix = sformat("phone=%s", phonenumber)
  418. local originData = {
  419. {key="phone", value=phonenumber},
  420. {key="game_id", value=gameid},
  421. {key="appid", value=appid},
  422. {key="type", value="login"},
  423. }
  424. local suffix = calcSuffix(originData)
  425. local header = getHeader()
  426. HTTPRequestPost(url, httpCB, suffix, header)
  427. releasePrint("RequestAuthCode url: " .. url .. " postData: " .. suffix)
  428. end
  429. function AuthProxy:RequestRegister(data)
  430. -- 2、普通注册
  431. local url = doamin2 .. url_register
  432. if not (url and string.len(url) > 0) then
  433. return nil
  434. end
  435. -- http数据请求回调
  436. local function httpCB(success, response)
  437. if not success then
  438. ShowSystemTips("[-1] 注册失败, 请求失败")
  439. return false
  440. end
  441. local jsonData = cjson.decode(response)
  442. if not jsonData then
  443. ShowSystemTips("[-2] 注册失败, 解析失败")
  444. return false
  445. end
  446. if not (jsonData.code == 200) then
  447. ShowSystemTips("[-3] 注册失败, 状态异常 " .. jsonData.msg)
  448. global.Facade:sendNotification(global.NoticeTable.AuthRegisterFailure, jsonData)
  449. return false
  450. end
  451. dump(jsonData)
  452. self._uid = jsonData.data.uid
  453. self._token = jsonData.data.token
  454. self._username = jsonData.data.username
  455. self._password = jsonData.data.password
  456. if global.L_NativeBridgeManager.SetCertification and global.L_NativeBridgeManager.SetAdult then
  457. if jsonData.data.age_status and tonumber(jsonData.data.age_status) == 0 then
  458. global.L_NativeBridgeManager:SetCertification(false)
  459. global.L_NativeBridgeManager:SetAdult(false)
  460. else
  461. global.L_NativeBridgeManager:SetCertification(true)
  462. local isAdult = jsonData.data.age_status and tonumber(jsonData.data.age_status) == 2
  463. global.L_NativeBridgeManager:SetAdult(isAdult)
  464. end
  465. end
  466. local jData = {}
  467. jData.userId = self._uid
  468. global.L_NativeBridgeManager:GN_umengUploadRegister(jData)
  469. -- notice
  470. global.Facade:sendNotification(global.NoticeTable.AuthRegisterSuccess, jsonData)
  471. end
  472. local originData = {
  473. {key="username", value=data.username},
  474. {key="password", value=data.password},
  475. {key="question", value=data.question},
  476. {key="answer", value=data.answer},
  477. {key="type", value=data.type},
  478. {key="game_id", value=gameid},
  479. {key="appid", value=appid},
  480. {key="promote_id", value=global.L_GameEnvManager:GetGMName()},
  481. }
  482. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  483. local registerDataRePort = DataRePortProxy:UserRegister()
  484. if registerDataRePort then
  485. table.insert(originData,{
  486. key="_device_info",
  487. value=registerDataRePort
  488. })
  489. end
  490. local suffix = calcSuffix(originData)
  491. local header = getHeader()
  492. HTTPRequestPost(url, httpCB, suffix, header)
  493. releasePrint("RequestRegister url: " .. url .. " postData: " .. suffix)
  494. end
  495. function AuthProxy:RequestLogin(data)
  496. -- 3、登陆接口
  497. local url = doamin2 .. url_login
  498. if not (url and string.len(url) > 0) then
  499. return nil
  500. end
  501. -- http数据请求回调
  502. local function httpCB(success, response)
  503. if not success then
  504. ShowSystemTips("[-1] 登录失败, 请求失败")
  505. return false
  506. end
  507. local jsonData = cjson.decode(response)
  508. if not jsonData then
  509. ShowSystemTips("[-2] 登录失败, 解析失败")
  510. return false
  511. end
  512. if not (jsonData.code == 200) then
  513. ShowSystemTips(jsonData.msg)
  514. return false
  515. end
  516. dump(jsonData)
  517. self._uid = jsonData.data.uid
  518. self._token = jsonData.data.token
  519. self._mobile = jsonData.data.mobile
  520. self._username = jsonData.data.username
  521. -- 0 未实名,2成年,3未成年
  522. if global.L_NativeBridgeManager.SetCertification and global.L_NativeBridgeManager.SetAdult then
  523. if jsonData.data.age_status and tonumber(jsonData.data.age_status) == 0 then
  524. global.L_NativeBridgeManager:SetCertification(false)
  525. global.L_NativeBridgeManager:SetAdult(false)
  526. global.Facade:sendNotification(global.NoticeTable.Layer_IdentifyID_Open, true)
  527. return
  528. else
  529. global.L_NativeBridgeManager:SetCertification(true)
  530. local isAdult = jsonData.data.age_status and tonumber(jsonData.data.age_status) == 2
  531. global.L_NativeBridgeManager:SetAdult(isAdult)
  532. end
  533. end
  534. local isBind = jsonData.data.mobile
  535. local isOpenTips = tonumber(jsonData.data.bind_phone) == 1
  536. if ( not isBind or string.len(isBind) == 0) and isOpenTips then
  537. --未绑定手机号
  538. local function callback(bType, custom)
  539. if bType == 1 then
  540. global.Facade:sendNotification(global.NoticeTable.AuthLoginSuccess, jsonData)
  541. elseif bType == 2 then
  542. local LoginAccountMediator = global.Facade:retrieveMediator( "LoginAccountMediator" )
  543. if LoginAccountMediator and LoginAccountMediator._layer then
  544. if not LoginAccountMediator._layer._isFetchAssets then
  545. return false
  546. end
  547. LoginAccountMediator._layer:ShowBindPhone()
  548. end
  549. end
  550. end
  551. local data = {}
  552. data.str = GET_STRING(700000101)
  553. data.btnDesc = { GET_STRING(700000102), GET_STRING(700000103)}
  554. data.callback = callback
  555. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  556. else
  557. -- notice
  558. ShowSystemTips("登录成功")
  559. global.Facade:sendNotification(global.NoticeTable.AuthLoginSuccess, jsonData)
  560. end
  561. end
  562. if data.type == 1 then
  563. self._username = data.username
  564. self._password = data.password
  565. end
  566. local platform = -1
  567. if global.isWindows then
  568. platform = 0
  569. elseif global.isAndroid or global.isOHOS then
  570. platform = 1
  571. elseif global.isIOS then
  572. platform = 2
  573. end
  574. local deviceid = nil
  575. if global.isWindows and getMac then
  576. deviceid = getMac()
  577. end
  578. local originData = {
  579. {key="username", value=data.username},
  580. {key="password", value=data.password},
  581. {key="type", value=data.type},
  582. {key="platform", value=platform},
  583. {key="game_id", value=gameid},
  584. {key="appid", value=appid},
  585. {key="device_id", value=deviceid},
  586. {key="promote_id", value=global.L_GameEnvManager:GetGMName()}
  587. }
  588. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  589. local loginDataRePort = DataRePortProxy:UserLogin()
  590. if loginDataRePort then
  591. table.insert(originData,{
  592. key="_device_info" ,
  593. value=loginDataRePort
  594. })
  595. end
  596. local suffix = calcSuffix(originData)
  597. local header = getHeader()
  598. HTTPRequestPost(url, httpCB, suffix, header)
  599. releasePrint("RequestLogin url: " .. url .. " postData: " .. suffix)
  600. end
  601. function AuthProxy:RequestLoginByPhone(data)
  602. -- 3、登陆接口 手机登录
  603. local url = doamin2 .. url_loginByPhone
  604. if not (url and string.len(url) > 0) then
  605. return nil
  606. end
  607. -- http数据请求回调
  608. local function httpCB(success, response)
  609. if not success then
  610. ShowSystemTips("[-1] 登录失败, 请求失败")
  611. return false
  612. end
  613. local jsonData = cjson.decode(response)
  614. if not jsonData then
  615. ShowSystemTips("[-2] 登录失败, 解析失败")
  616. return false
  617. end
  618. if not (jsonData.code == 200) then
  619. ShowSystemTips("[-3] 登录失败, 状态异常 " .. jsonData.msg)
  620. return false
  621. end
  622. dump(jsonData)
  623. self._uid = jsonData.data.uid
  624. self._token = jsonData.data.token
  625. self._mobile = jsonData.data.mobile
  626. self._username = jsonData.data.username
  627. -- 0 未实名,2成年,3未成年
  628. if global.L_NativeBridgeManager.SetCertification and global.L_NativeBridgeManager.SetAdult then
  629. if jsonData.data.age_status and tonumber(jsonData.data.age_status) == 0 then
  630. global.L_NativeBridgeManager:SetCertification(false)
  631. global.L_NativeBridgeManager:SetAdult(false)
  632. else
  633. global.L_NativeBridgeManager:SetCertification(true)
  634. local isAdult = jsonData.data.age_status and tonumber(jsonData.data.age_status) == 2
  635. global.L_NativeBridgeManager:SetAdult(isAdult)
  636. end
  637. end
  638. -- notice
  639. global.Facade:sendNotification(global.NoticeTable.AuthLoginSuccess, jsonData)
  640. end
  641. self._mobile = data.phoneId
  642. local originData = {
  643. {key="phone", value=data.phoneId},
  644. {key="code", value=data.authCode},
  645. {key="game_id", value=gameid},
  646. {key="appid", value=appid},
  647. {key="promote_id", value=global.L_GameEnvManager:GetGMName()}
  648. }
  649. local suffix = calcSuffix(originData)
  650. local header = getHeader()
  651. HTTPRequestPost(url, httpCB, suffix, header)
  652. releasePrint("RequestLogin url: " .. url .. " postData: " .. suffix)
  653. end
  654. function AuthProxy:RequestVisitor(data)
  655. -- 4、游客登陆接口
  656. local url = doamin .. url_visitor
  657. if not (url and string.len(url) > 0) then
  658. return nil
  659. end
  660. -- http数据请求回调
  661. local function httpCB(success, response)
  662. if not success then
  663. ShowSystemTips("[-1] 游客登录失败, 请求失败")
  664. return false
  665. end
  666. local jsonData = cjson.decode(response)
  667. if not jsonData then
  668. ShowSystemTips("[-2] 游客登录失败, 解析失败")
  669. return false
  670. end
  671. if not (jsonData.status == 1) then
  672. ShowSystemTips("[-3] 游客登录失败, 状态异常 " .. jsonData.status .. jsonData.msg)
  673. return false
  674. end
  675. dump(jsonData)
  676. self._uid = jsonData.data.uid
  677. self._token = jsonData.data.token
  678. self._mobile = jsonData.data.mobile
  679. self._username = jsonData.data.username
  680. self._password = jsonData.data.password
  681. -- notice
  682. global.Facade:sendNotification(global.NoticeTable.AuthVisitorSuccess, jsonData)
  683. end
  684. local originData = {
  685. {key="game_id", value=gameid},
  686. {key="appid", value=appid},
  687. {key="promote_id", value=global.L_GameEnvManager:GetGMName()},
  688. }
  689. local suffix = calcSuffix(originData)
  690. local header = getHeader()
  691. HTTPRequestPost(url, httpCB, suffix, header)
  692. releasePrint("RequestVisitor url: " .. url .. " postData: " .. suffix)
  693. end
  694. function AuthProxy:RequestForgetPassword(data)
  695. -- 5、用户忘记密码
  696. local url = doamin .. url_forgetpwd
  697. if not (url and string.len(url) > 0) then
  698. return nil
  699. end
  700. -- http数据请求回调
  701. local function httpCB(success, response)
  702. if not success then
  703. ShowSystemTips("[-1] 修改密码失败, 请求失败")
  704. return false
  705. end
  706. local jsonData = cjson.decode(response)
  707. if not jsonData then
  708. ShowSystemTips("[-2] 修改密码失败, 解析失败")
  709. return false
  710. end
  711. if not (jsonData.status == 1) then
  712. ShowSystemTips("[-3] 修改密码失败, 状态异常 " .. jsonData.status .. jsonData.msg)
  713. return false
  714. end
  715. dump(jsonData)
  716. end
  717. local originData = {
  718. {key="phone", value=data.phonenumber},
  719. {key="code", value=data.code},
  720. {key="newpassword", value=data.newpassword},
  721. {key="appid", value=appid},
  722. }
  723. local suffix = calcSuffix(originData)
  724. local header = getHeader()
  725. HTTPRequestPost(url, httpCB, suffix, header)
  726. releasePrint("RequestForgetPassword url: " .. url .. " postData: " .. suffix)
  727. end
  728. function AuthProxy:RequestBindPhoneByMb(data)
  729. -- 6、绑定手机
  730. local url = doamin2 .. url_bindPhoneByMb
  731. if not (url and string.len(url) > 0) then
  732. return nil
  733. end
  734. -- http数据请求回调
  735. local function httpCB(success, response)
  736. if not success then
  737. ShowSystemTips("[-1] 密保绑定手机失败, 请求失败")
  738. return false
  739. end
  740. local jsonData = cjson.decode(response)
  741. if not jsonData then
  742. ShowSystemTips("[-2] 密保绑定手机失败, 解析失败")
  743. return false
  744. end
  745. if not (jsonData.code == 200) then
  746. ShowSystemTips("[-3] 密保绑定手机失败, 状态异常 " .. jsonData.msg)
  747. return false
  748. end
  749. dump(jsonData)
  750. ShowSystemTips("手机号绑定成功")
  751. global.Facade:sendNotification(global.NoticeTable.AuthBindPhoneResp, jsonData)
  752. end
  753. local originData = {
  754. {key="username", value=data.username},
  755. {key="answer", value=data.answer},
  756. {key="phone", value=data.phone},
  757. {key="code", value=data.code},
  758. {key="appid", value=appid},
  759. {key="game_id", value=gameid}
  760. }
  761. local suffix = calcSuffix(originData)
  762. local header = getHeader()
  763. HTTPRequestPost(url, httpCB, suffix, header)
  764. releasePrint("RequestBindPhoneByMb url: " .. url .. " postData: " .. suffix)
  765. end
  766. function AuthProxy:RequestChangePhone(data)
  767. -- 6、 换绑手机
  768. local url = doamin2 .. url_changePhone
  769. if not (url and string.len(url) > 0) then
  770. return nil
  771. end
  772. -- http数据请求回调
  773. local function httpCB(success, response)
  774. if not success then
  775. ShowSystemTips("[-1] 绑定手机失败, 请求失败")
  776. return false
  777. end
  778. local jsonData = cjson.decode(response)
  779. if not jsonData then
  780. ShowSystemTips("[-2] 密保绑定手机失败, 解析失败")
  781. return false
  782. end
  783. if not (jsonData.code == 200) then
  784. ShowSystemTips("[-3] 密保绑定手机失败, 状态异常 " .. jsonData.msg)
  785. return false
  786. end
  787. dump(jsonData)
  788. ShowSystemTips("手机号修改成功")
  789. global.Facade:sendNotification(global.NoticeTable.AuthBindPhoneResp, jsonData)
  790. end
  791. local originData = {
  792. {key="username", value=data.username},
  793. {key="phone", value=data.phone},
  794. {key="code", value=data.code},
  795. {key="phone_new", value=data.phone_new},
  796. {key="code_new", value=data.code_new},
  797. {key="appid", value=appid},
  798. {key="game_id", value=gameid},
  799. }
  800. local suffix = calcSuffix(originData)
  801. local header = getHeader()
  802. HTTPRequestPost(url, httpCB, suffix, header)
  803. releasePrint("RequestChangePhone url: " .. url .. " postData: " .. suffix)
  804. end
  805. function AuthProxy:RequestChangePwdByPhone(data)
  806. -- 7、修改密码
  807. local url = doamin2 .. url_changepwdByPhone
  808. if not (url and string.len(url) > 0) then
  809. return nil
  810. end
  811. -- http数据请求回调
  812. local function httpCB(success, response)
  813. if not success then
  814. ShowSystemTips("[-1] 手机修改密码失败, 请求失败")
  815. return false
  816. end
  817. local jsonData = cjson.decode(response)
  818. if not jsonData then
  819. ShowSystemTips("[-2] 手机修改密码失败, 解析失败")
  820. return false
  821. end
  822. if not (jsonData.code == 200) then
  823. ShowSystemTips("[-3] 手机修改密码失败, 状态异常 " .. jsonData.msg)
  824. return false
  825. end
  826. dump(jsonData)
  827. ShowSystemTips("修改成功,请牢记您的新密码")
  828. self._username = data.username
  829. self._password = data.newpassword
  830. global.Facade:sendNotification(global.NoticeTable.AuthChangePwdByPhoneResp, jsonData)
  831. end
  832. local originData = {
  833. {key="username", value=data.username},
  834. {key="phone", value=data.phone},
  835. {key="code", value=data.code},
  836. {key="newpassword", value=data.newpassword},
  837. {key="appid", value=appid},
  838. {key="game_id", value=gameid},
  839. }
  840. local suffix = calcSuffix(originData)
  841. local header = getHeader()
  842. HTTPRequestPost(url, httpCB, suffix, header)
  843. releasePrint("RequestChangePassword url: " .. url .. " postData: " .. suffix)
  844. end
  845. function AuthProxy:RequestChangePwdByMb(data)
  846. -- 7、修改密码
  847. local url = doamin2 .. url_changepwdByMb
  848. if not (url and string.len(url) > 0) then
  849. return nil
  850. end
  851. -- http数据请求回调
  852. local function httpCB(success, response)
  853. if not success then
  854. ShowSystemTips("[-1] 密保修改密码失败, 请求失败")
  855. return false
  856. end
  857. local jsonData = cjson.decode(response)
  858. if not jsonData then
  859. ShowSystemTips("[-2] 密保修改密码失败, 解析失败")
  860. return false
  861. end
  862. if not (jsonData.code == 200) then
  863. ShowSystemTips("[-3] 密保修改密码失败, 状态异常 " .. jsonData.msg)
  864. return false
  865. end
  866. dump(jsonData)
  867. ShowSystemTips("修改成功,请牢记您的新密码")
  868. self._username = data.username
  869. self._password = data.newpassword
  870. global.Facade:sendNotification(global.NoticeTable.AuthChangePwdResp, jsonData)
  871. end
  872. local originData = {
  873. {key="username", value=data.username},
  874. {key="answer", value=data.answer},
  875. {key="newpassword", value=data.newpassword},
  876. {key="appid", value=appid},
  877. {key="game_id", value=gameid},
  878. }
  879. local suffix = calcSuffix(originData)
  880. local header = getHeader()
  881. HTTPRequestPost(url, httpCB, suffix, header)
  882. releasePrint("RequestChangePwdByMb url: " .. url .. " postData: " .. suffix)
  883. end
  884. function AuthProxy:RequestChangeMb(data)
  885. -- 修改密保
  886. local url = doamin2 .. url_changeMb
  887. if not (url and string.len(url) > 0) then
  888. return nil
  889. end
  890. -- http数据请求回调
  891. local function httpCB(success, response)
  892. if not success then
  893. ShowSystemTips("[-1] 修改密保失败, 请求失败")
  894. return false
  895. end
  896. local jsonData = cjson.decode(response)
  897. if not jsonData then
  898. ShowSystemTips("[-2] 修改密保失败, 解析失败")
  899. return false
  900. end
  901. if not (jsonData.code == 200) then
  902. ShowSystemTips("[-3] 修改密保失败, 状态异常 " .. jsonData.msg)
  903. return false
  904. end
  905. dump(jsonData)
  906. ShowSystemTips("修改成功,请牢记您的新密保")
  907. self._username = data.username
  908. self._password = data.password
  909. global.Facade:sendNotification(global.NoticeTable.AuthChangeMbResp, jsonData)
  910. end
  911. local originData = {
  912. {key="username", value=data.username},
  913. {key="password", value=data.password},
  914. {key="question", value=data.question},
  915. {key="answer", value=data.answer},
  916. {key="question_new",value=data.question_new},
  917. {key="answer_new", value=data.answer_new},
  918. {key="appid", value=appid},
  919. {key="game_id", value=gameid},
  920. }
  921. local suffix = calcSuffix(originData)
  922. local header = getHeader()
  923. HTTPRequestPost(url, httpCB, suffix, header)
  924. releasePrint("RequestChangeMb url: " .. url .. " postData: " .. suffix)
  925. end
  926. function AuthProxy:RequestCheckToken(uid, token)
  927. -- 8、验证token有效性 成功后刷新token
  928. local url = doamin2 .. url_checkToken
  929. if not (url and string.len(url) > 0) then
  930. return nil
  931. end
  932. -- http数据请求回调
  933. local function httpCB(success, response)
  934. if not success then
  935. ShowSystemTips("[-1] 快速登录失败, 请求失败")
  936. return false
  937. end
  938. local jsonData = cjson.decode(response)
  939. if not jsonData then
  940. ShowSystemTips("[-2] 快速登录失败, 解析失败")
  941. return false
  942. end
  943. if not (jsonData.code == 200) then
  944. ShowSystemTips("[-3] 快速登录失败, 状态异常 " .. jsonData.msg)
  945. -- token验证失败,清空已存储token
  946. self._token = ""
  947. -- notice
  948. global.Facade:sendNotification(global.NoticeTable.AuthCheckTokenFailure, jsonData)
  949. return false
  950. end
  951. dump(jsonData)
  952. self._uid = jsonData.data.uid
  953. self._token = jsonData.data.token
  954. self._mobile = jsonData.data.mobile
  955. self._username = jsonData.data.username
  956. if global.L_NativeBridgeManager.SetCertification and global.L_NativeBridgeManager.SetAdult then
  957. if jsonData.data.age_status and tonumber(jsonData.data.age_status) == 0 then
  958. global.L_NativeBridgeManager:SetCertification(false)
  959. global.L_NativeBridgeManager:SetAdult(false)
  960. else
  961. global.L_NativeBridgeManager:SetCertification(true)
  962. local isAdult = jsonData.data.age_status and tonumber(jsonData.data.age_status) == 2
  963. global.L_NativeBridgeManager:SetAdult(isAdult)
  964. end
  965. end
  966. -- notice
  967. global.Facade:sendNotification(global.NoticeTable.AuthCheckTokenSuccess, jsonData)
  968. end
  969. local originData = {
  970. {key="uid", value=uid},
  971. {key="token", value=token},
  972. {key="game_id", value=gameid},
  973. {key="appid", value=appid},
  974. {key="promote_id", value=global.L_GameEnvManager:GetGMName()}
  975. }
  976. local suffix = calcSuffix(originData)
  977. local header = getHeader()
  978. header["X-Token"] = token
  979. HTTPRequestPost(url, httpCB, suffix, header)
  980. releasePrint("RequestCheckToken url: " .. url .. " postData: " .. suffix)
  981. end
  982. function AuthProxy:RequestAlipay(payData, orderCB)
  983. -- 支付宝支付
  984. local url = doamin .. (self._isSDKPay and url_alipay_sdk or url_alipay)
  985. if self._isXZPay then
  986. url = doamin .. xz_url_pay
  987. end
  988. if not (url and string.len(url) > 0) then
  989. if orderCB then
  990. orderCB()
  991. end
  992. return nil
  993. end
  994. -- http数据请求回调
  995. local function httpCB(success, response)
  996. if orderCB then
  997. orderCB()
  998. end
  999. if not success then
  1000. ShowSystemTips("[-1] ALIPAY ERROR")
  1001. return false
  1002. end
  1003. local jsonData = cjson.decode(response)
  1004. if not jsonData then
  1005. ShowSystemTips("[-2] ALIPAY ERROR")
  1006. return false
  1007. end
  1008. if not (jsonData.status == 1) then
  1009. ShowSystemTips("[-3] ALIPAY ERROR, code: " .. jsonData.status .. jsonData.msg)
  1010. return false
  1011. end
  1012. if not (jsonData.data and jsonData.data.order) then
  1013. ShowSystemTips("[-4] ALIPAY ERROR")
  1014. return false
  1015. end
  1016. releasePrint(cjson.encode(jsonData))
  1017. dump(jsonData)
  1018. -- notify native and do something
  1019. if self._isSDKPay or self._isXZPay then
  1020. cc.Application:getInstance():openURL(jsonData.data.order)
  1021. else
  1022. global.L_NativeBridgeManager:GN_onCallOF({orderInfo = jsonData.data.order})
  1023. end
  1024. end
  1025. local originData = clone(payData)
  1026. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  1027. local prePayDataRePort = DataRePortProxy:PrePay()
  1028. if prePayDataRePort then
  1029. table.insert(originData,{
  1030. key="_device_info" ,
  1031. value=prePayDataRePort,
  1032. })
  1033. end
  1034. local suffix = calcSuffix(originData)
  1035. local header = getHeader()
  1036. HTTPRequestPost(url, httpCB, suffix, header)
  1037. releasePrint("RequestAlipay url: " .. url .. " postData: " .. suffix)
  1038. end
  1039. function AuthProxy:RequestWXpay(payData, orderCB)
  1040. local function openWebView(url, referer)
  1041. if false == global.isMobile then
  1042. print("++++++++++++++++++++++++++mobile only")
  1043. return
  1044. end
  1045. if self._webView and not tolua.isnull(self._webView) then
  1046. self._webView:removeFromParent()
  1047. self._webView = nil
  1048. end
  1049. local viewURL = url
  1050. local winSize = cc.Director:getInstance():getVisibleSize()
  1051. self._webView = ccexp.CustomView and ccexp.CustomView:create() or ccexp.WebView:create()
  1052. if referer then
  1053. if global.isIOS then
  1054. referer = string.gsub(referer, "http://", "")
  1055. referer = string.sub(referer, 1, string.len(referer) - 1)
  1056. referer = referer .. "://"
  1057. self._webView:setReferer(referer)
  1058. else
  1059. self._webView:setReferer(referer)
  1060. end
  1061. end
  1062. self._webView:setPosition(winSize.width / 2, winSize.height / 2)
  1063. self._webView:setContentSize(winSize.width / 2, winSize.height / 2)
  1064. self._webView:setOnShouldStartLoading(function(sender, url)
  1065. releasePrint("onWebViewShouldStartLoading, url is ", url)
  1066. return true
  1067. end)
  1068. self._webView:setOnDidFinishLoading(function(sender, a_url)
  1069. releasePrint("onWebViewDidFinishLoading, url is ", url)
  1070. end)
  1071. self._webView:setOnDidFailLoading(function(sender, url)
  1072. releasePrint("setOnDidFailLoading, url is ", url)
  1073. end)
  1074. local ui_root = global.Director:getRunningScene()
  1075. self._webView:setVisible(false)
  1076. ui_root:addChild(self._webView, 999)
  1077. self._webView:loadURL(viewURL)
  1078. end
  1079. -- 微信支付
  1080. local url = doamin .. (self._isSDKPay and url_weixin_sdk or url_weixin)
  1081. if self._isXZPay then
  1082. url = doamin .. xz_url_pay
  1083. end
  1084. if not (url and string.len(url) > 0) then
  1085. if orderCB then
  1086. orderCB(false)
  1087. end
  1088. return nil
  1089. end
  1090. -- http数据请求回调
  1091. local function httpCB(success, response)
  1092. if orderCB then
  1093. orderCB()
  1094. end
  1095. if not success then
  1096. ShowSystemTips("[-1] WXPAY ERROR")
  1097. releasePrint("request wxpay failed, code: -1 [request failed]")
  1098. return false
  1099. end
  1100. local jsonData = cjson.decode(response)
  1101. if not jsonData then
  1102. ShowSystemTips("[-2] WXPAY ERROR")
  1103. releasePrint("request wxpay failed, code: -2 [parse failed]")
  1104. return false
  1105. end
  1106. if not (jsonData.status == 1) then
  1107. ShowSystemTips("[-3] WXPAY ERROR, code: " .. jsonData.status .. jsonData.msg)
  1108. releasePrint("request wxpay failed, code: " .. jsonData.status .. jsonData.msg)
  1109. return false
  1110. end
  1111. if not (jsonData.data and jsonData.data.url and jsonData.data.referer) then
  1112. ShowSystemTips("[-4] WXPAY ERROR")
  1113. releasePrint("request wxpay failed, code: -3 [url or referer failed]")
  1114. return false
  1115. end
  1116. releasePrint(cjson.encode(jsonData))
  1117. dump(jsonData)
  1118. if self._isSDKPay then
  1119. cc.Application:getInstance():openURL(jsonData.data.order)
  1120. else
  1121. releasePrint(jsonData.data.url .. "referer: " .. jsonData.data.referer)
  1122. openWebView(jsonData.data.url, jsonData.data.referer)
  1123. end
  1124. end
  1125. local originData = clone(payData)
  1126. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  1127. local prePayDataRePort = DataRePortProxy:PrePay()
  1128. if prePayDataRePort then
  1129. table.insert(originData,{
  1130. key="_device_info",
  1131. value=prePayDataRePort
  1132. })
  1133. end
  1134. local suffix = calcSuffix(originData)
  1135. local header = getHeader()
  1136. HTTPRequestPost(url, httpCB, suffix, header)
  1137. releasePrint("RequestWXpay url: " .. url .. " postData: " .. suffix)
  1138. end
  1139. function AuthProxy:RequestIdentifyID(data)
  1140. --实名认证接口
  1141. local url = doamin2 .. url_identify
  1142. if not (url and string.len(url) > 0) then
  1143. return nil
  1144. end
  1145. if not self:IsValidToken() then
  1146. ShowSystemTips("请登录后操作")
  1147. return
  1148. end
  1149. -- http数据请求回调
  1150. local function httpCB(success, response)
  1151. if not success then
  1152. ShowSystemTips("[-1] 实名认证失败, 请求失败")
  1153. return false
  1154. end
  1155. local jsonData = cjson.decode(response)
  1156. if not jsonData then
  1157. ShowSystemTips("[-2] 实名认证失败, 解析失败")
  1158. return false
  1159. end
  1160. if not (jsonData.code == 200) then
  1161. ShowSystemTips("[-3] 实名认证失败, 状态异常 " .. jsonData.msg)
  1162. return false
  1163. end
  1164. dump(jsonData)
  1165. if global.L_NativeBridgeManager.SetCertification and global.L_NativeBridgeManager.SetAdult then
  1166. if jsonData.data.age_status and tonumber(jsonData.data.age_status) == 0 then
  1167. global.L_NativeBridgeManager:SetCertification(false)
  1168. global.L_NativeBridgeManager:SetAdult(false)
  1169. else
  1170. ShowSystemTips("实名认证成功")
  1171. global.L_NativeBridgeManager:SetCertification(true)
  1172. local isAdult = jsonData.data.age_status and tonumber(jsonData.data.age_status) == 2
  1173. global.L_NativeBridgeManager:SetAdult(isAdult)
  1174. global.Facade:sendNotification(global.NoticeTable.AuthChangePwdResp)
  1175. end
  1176. end
  1177. end
  1178. local originData = {
  1179. {key="name", value=data.name},
  1180. {key="idcard", value=data.IDNumber},
  1181. {key="game_id", value=gameid},
  1182. {key="appid", value=appid},
  1183. }
  1184. local suffix = calcSuffix(originData)
  1185. local header = getHeader()
  1186. header["X-Token"] = self:GetToken()
  1187. HTTPRequestPost(url, httpCB, suffix, header)
  1188. releasePrint("RequestIdentify url: " .. url .. " postData: " .. suffix)
  1189. end
  1190. ----------------------------------------------------------
  1191. -- 二维码支付
  1192. function AuthProxy:RequestQRCodePay(payChannel, payData, orderCB)
  1193. local url = nil
  1194. if self.PAY_CHANNEL.WEIXIN == payChannel then
  1195. url = self._isSDKPay and (doamin .. url_qrcode_weixin_sdk) or (newDoamin2 .. url_qrcode_weixin)
  1196. elseif self.PAY_CHANNEL.ALIPAY == payChannel or self.PAY_CHANNEL.HUABEI == payChannel then
  1197. url = self._isSDKPay and (doamin .. url_qrcode_alipay_sdk) or (newDoamin2 .. url_qrcode_alipay)
  1198. end
  1199. if self._isXZPay then
  1200. url = doamin .. xz_qrcode_pay
  1201. end
  1202. if not (url and string.len(url) > 0) then
  1203. if orderCB then
  1204. orderCB(false)
  1205. end
  1206. return nil
  1207. end
  1208. -- http数据请求回调
  1209. local function httpCB(success, response)
  1210. if not success then
  1211. ShowSystemTips("QRCODEPAY ERROR [-1]")
  1212. if orderCB then
  1213. orderCB(false)
  1214. end
  1215. return false
  1216. end
  1217. print(response)
  1218. local jsonData = cjson.decode(response)
  1219. if not jsonData then
  1220. ShowSystemTips("QRCODEPAY ERROR [-2]")
  1221. if orderCB then
  1222. orderCB(false)
  1223. end
  1224. return false
  1225. end
  1226. jsonData.status = jsonData.status or jsonData.data.status or 0
  1227. if not (jsonData.status == 1) then
  1228. ShowSystemTips("QRCODEPAY ERROR [-3] " .. jsonData.status .. jsonData.msg)
  1229. if orderCB then
  1230. orderCB(false)
  1231. end
  1232. return false
  1233. end
  1234. if not (jsonData.data and jsonData.data.order_no) then
  1235. ShowSystemTips("QRCODEPAY ERROR [-4]")
  1236. if orderCB then
  1237. orderCB(false)
  1238. end
  1239. return false
  1240. end
  1241. dump(jsonData)
  1242. -- 请求支付二维码
  1243. local originData = {
  1244. {key="order_no", value=jsonData.data.order_no},
  1245. }
  1246. local suffix = calcSuffix(originData)
  1247. local get_qrcode_url = self._isXZPay and (doamin .. xz_get_qrcode) or (newDoamin2 .. url_get_qrcode)
  1248. local url = string.format("%s?%s", get_qrcode_url, suffix)
  1249. orderCB(true, url)
  1250. end
  1251. local originData = clone(payData)
  1252. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  1253. local prePayDataRePort = DataRePortProxy:PrePay()
  1254. if prePayDataRePort then
  1255. table.insert(originData,{
  1256. key="_device_info",
  1257. value=prePayDataRePort
  1258. })
  1259. end
  1260. local suffix = calcSuffix(originData)
  1261. local header = getHeader()
  1262. HTTPRequestPost(url, httpCB, suffix, header)
  1263. releasePrint("RequestQRCodePay url: " .. url .. " postData: " .. suffix)
  1264. end
  1265. function AuthProxy:RequestPay(payType, payChannel, productData, qrcodeCB)
  1266. local timeMS = socket.gettime() * 10000
  1267. local trade_no = productData.orderid
  1268. self._orderId = trade_no
  1269. local GMSdkPay = self._isXZPay
  1270. local pay_way = nil
  1271. if GMSdkPay and self.PAY_TYPE.QRCODE == payType then
  1272. pay_way = 7
  1273. elseif GMSdkPay and self.PAY_TYPE.NATIVE == payType then
  1274. if self.PAY_CHANNEL.ALIPAY == payChannel or self.PAY_CHANNEL.HUABEI == payChannel then
  1275. pay_way = 5
  1276. elseif self.PAY_CHANNEL.WEIXIN == payChannel then
  1277. pay_way = 6
  1278. end
  1279. else
  1280. if self.PAY_CHANNEL.ALIPAY == payChannel then
  1281. pay_way = 3
  1282. elseif self.PAY_CHANNEL.HUABEI == payChannel then
  1283. pay_way = 20
  1284. elseif self.PAY_CHANNEL.WEIXIN == payChannel then
  1285. pay_way = 4
  1286. end
  1287. end
  1288. -- 请求支付
  1289. local payData = {
  1290. {key="uid", value=self._uid},
  1291. {key="appid", value=appid},
  1292. {key="game_id", value=gameid},
  1293. {key="promote_id", value=global.L_GameEnvManager:GetGMName()},
  1294. {key="role_id", value=productData.roleId},
  1295. {key="server_id", value=productData.serverId},
  1296. {key="role_name", value=productData.roleName},
  1297. {key="server_name", value=productData.serverName},
  1298. {key="trade_no", value=trade_no},
  1299. {key="payplatform2cp", value=productData.currencyID},
  1300. {key="props_name", value=productData.productName},
  1301. {key="price", value=productData.productPrice},
  1302. {key="is_huabei", value=(self.PAY_CHANNEL.HUABEI == payChannel and 1 or 0)},
  1303. {key="pay_way", value=pay_way},
  1304. }
  1305. local PlayerPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  1306. table.insert(payData,{key="job_id", value=PlayerPropertyProxy:GetRoleJob()})
  1307. table.insert(payData,{key="job_name", value=PlayerPropertyProxy:GetRoleJobName() or ""})
  1308. table.insert(payData,{key="role_level", value=PlayerPropertyProxy:GetRoleLevel()})
  1309. table.insert(payData,{key="prod_name", value=productData.productName or ""})
  1310. table.insert(payData,{key="main_servid", value=productData.main_servid})
  1311. table.insert(payData,{key="main_server_name", value=productData.main_server_name})
  1312. local pc_version = nil
  1313. local roomid = nil
  1314. local isBoxLogin = global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin") and global.L_GameEnvManager:GetEnvDataByKey("isBoxLogin") == 1
  1315. if isBoxLogin and global.isWindows then
  1316. local pc_version = 3
  1317. local roomid = global.L_GameEnvManager:GetEnvDataByKey("roomid") or 0 --进入游戏的直播房号
  1318. table.insert( payData, {key="sdk_version", value=pc_version})
  1319. table.insert( payData, {key="live_no", value=roomid} )
  1320. end
  1321. -- 支付
  1322. ShowLoadingBar(3)
  1323. if self.PAY_TYPE.QRCODE == payType then
  1324. -- 二维码
  1325. -- 下单成功自动下载二维码
  1326. local function orderCB(isOk, qrcodeURL)
  1327. HideLoadingBar()
  1328. if isOk then
  1329. self:DownloadQRCode(qrcodeURL, qrcodeCB)
  1330. else
  1331. qrcodeCB(false)
  1332. end
  1333. end
  1334. if isBoxLogin then
  1335. local function getSceneCB(isOk)
  1336. self:RequestQRCodePay(payChannel, payData, orderCB)
  1337. end
  1338. local function httpCB(success, response)
  1339. if not success then
  1340. getSceneCB()
  1341. return false
  1342. end
  1343. print(response)
  1344. local jsonData = cjson.decode(response)
  1345. if not jsonData then
  1346. getSceneCB()
  1347. return false
  1348. end
  1349. if not (jsonData.code == 200) then
  1350. releasePrint("PCBOX GETSCENEINFO ERROR [-3] ".. jsonData.code .. jsonData.msg)
  1351. getSceneCB()
  1352. return false
  1353. end
  1354. if jsonData.data then
  1355. table.insert( payData, {key="scene", value=jsonData.data.scene})
  1356. for _, v in pairs(payData) do
  1357. if v.key and v.key == "live_no" then
  1358. local live_no = v.value
  1359. v.value = jsonData.data.live_no or live_no
  1360. break
  1361. end
  1362. end
  1363. end
  1364. dump(jsonData)
  1365. self:RequestQRCodePay(payChannel, payData, orderCB)
  1366. end
  1367. local originData = {
  1368. {key="game_id", value=gameid},
  1369. {key="user_id", value=self:GetUID()}
  1370. }
  1371. local suffix = calcBoxSignSuffix(originData, boxSceneSignKey)
  1372. local header = getHeader()
  1373. header["token"] = self:GetToken()
  1374. HTTPRequestPost(domain_boxN .. url_getSceneInfo, httpCB, suffix, header)
  1375. releasePrint("RequestGetSceneInfo url: " .. domain_boxN .. url_getSceneInfo .. " postData: " .. suffix)
  1376. else
  1377. self:RequestQRCodePay(payChannel, payData, orderCB)
  1378. end
  1379. elseif self.PAY_TYPE.NATIVE == payType then
  1380. local function orderCB(isOk)
  1381. HideLoadingBar()
  1382. end
  1383. -- 原生 支付
  1384. if self.PAY_CHANNEL.ALIPAY == payChannel or self.PAY_CHANNEL.HUABEI == payChannel then
  1385. -- 支付宝
  1386. self:RequestAlipay(payData, orderCB)
  1387. elseif self.PAY_CHANNEL.WEIXIN == payChannel then
  1388. -- 微信
  1389. self:RequestWXpay(payData, orderCB)
  1390. end
  1391. end
  1392. -- 友盟 发起充值上报
  1393. if global.L_NativeBridgeManager.GN_umengSubmitPay then
  1394. local uploadData = {
  1395. userId = tostring( self:GetUID() ),
  1396. orderId = tostring( trade_no ),
  1397. productId = tostring( productData.currencyID ),
  1398. productName = tostring( productData.productName ),
  1399. productPrice = tostring( productData.productPrice ),
  1400. }
  1401. global.L_NativeBridgeManager:GN_umengSubmitPay(uploadData)
  1402. end
  1403. end
  1404. function AuthProxy:DownloadQRCode(url, qrcodeCB)
  1405. local directoryPath = global.FileUtilCtl:getWritablePath() .. global.L_ModuleManager:GetCurrentModulePath()
  1406. local filename = "qrcode.png"
  1407. local filePath = directoryPath .. filename
  1408. local qrcodeURL = url
  1409. -- remove texture cache
  1410. local textureCache = global.Director:getTextureCache()
  1411. if textureCache:getTextureForKey(filePath) then
  1412. textureCache:removeTextureForKey(filePath)
  1413. end
  1414. -- check directory & create directory
  1415. if not global.FileUtilCtl:isDirectoryExist(directoryPath) then
  1416. global.FileUtilCtl:createDirectory(directoryPath)
  1417. end
  1418. -- check file & remove file
  1419. if global.FileUtilCtl:isFileExist(filePath) then
  1420. global.FileUtilCtl:removeFile(filePath)
  1421. global.FileUtilCtl:purgeCachedEntries()
  1422. end
  1423. -- download qrcode
  1424. global.HttpDownloader:AsyncDownloadEasy(
  1425. qrcodeURL,
  1426. filePath,
  1427. function(isOK)
  1428. print("download qrcode isOK", isOK)
  1429. HideLoadingBar()
  1430. if false == isOK then
  1431. ShowSystemTips(GET_STRING(30103202))
  1432. end
  1433. if qrcodeCB then
  1434. qrcodeCB(isOK, filename)
  1435. end
  1436. end,
  1437. 0
  1438. )
  1439. ShowLoadingBar(3)
  1440. -- for debug
  1441. releasePrint("---------------------------------------------- download qrcode")
  1442. releasePrint("url: " .. qrcodeURL)
  1443. end
  1444. ----------------------------------------------------------------
  1445. --- 聚合
  1446. ---
  1447. local function calcJuheSuffix(originData, secret_key, unlencode, pc_sign)
  1448. -- ascii排序
  1449. table.sort(originData, function(a, b)
  1450. return a.key < b.key
  1451. end)
  1452. -- 拼接
  1453. local origin = ""
  1454. for i, v in ipairs(originData) do
  1455. if v and v.key and v.value and string.len(v.key) > 0 and string.len(v.value) > 0 then
  1456. if unlencode then
  1457. origin = origin .. string.format("%s=%s", v.key, urlencodeT(v.value))
  1458. else
  1459. origin = origin .. string.format("%s=%s", v.key, v.value)
  1460. end
  1461. origin = origin .. "&"
  1462. end
  1463. end
  1464. origin = string.sub(origin, 1, string.len(origin)-1)
  1465. print("calcSuffix", origin .. secret_key)
  1466. --
  1467. local signMD5 = get_str_MD5(origin .. secret_key)
  1468. local suffix = origin .. "&" .. string.format("sign=%s", signMD5)
  1469. if pc_sign then
  1470. suffix = origin .. "&" .. string.format("pc_sign=%s", signMD5)
  1471. end
  1472. return suffix
  1473. end
  1474. local function encodeBase64(source_str)
  1475. local b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  1476. local s64 = ''
  1477. local str = source_str
  1478. while #str > 0 do
  1479. local bytes_num = 0
  1480. local buf = 0
  1481. for byte_cnt=1,3 do
  1482. buf = (buf * 256)
  1483. if #str > 0 then
  1484. buf = buf + string.byte(str, 1, 1)
  1485. str = string.sub(str, 2)
  1486. bytes_num = bytes_num + 1
  1487. end
  1488. end
  1489. for group_cnt=1,(bytes_num+1) do
  1490. local b64char = math.fmod(math.floor(buf/262144), 64) + 1
  1491. s64 = s64 .. string.sub(b64chars, b64char, b64char)
  1492. buf = buf * 64
  1493. end
  1494. for fill_cnt=1,(3-bytes_num) do
  1495. s64 = s64 .. '='
  1496. end
  1497. end
  1498. return s64
  1499. end
  1500. function AuthProxy:DownloadJuheQRCode(url, qrcodeCB)
  1501. local directoryPath = global.FileUtilCtl:getWritablePath() .. global.L_ModuleManager:GetCurrentModulePath()
  1502. local filename = "qrcode.png"
  1503. local filePath = directoryPath .. filename
  1504. local qrcodeURL = url
  1505. -- remove texture cache
  1506. local textureCache = global.Director:getTextureCache()
  1507. if textureCache:getTextureForKey(filePath) then
  1508. textureCache:removeTextureForKey(filePath)
  1509. end
  1510. -- check directory & create directory
  1511. if not global.FileUtilCtl:isDirectoryExist(directoryPath) then
  1512. global.FileUtilCtl:createDirectory(directoryPath)
  1513. end
  1514. -- check file & remove file
  1515. if global.FileUtilCtl:isFileExist(filePath) then
  1516. global.FileUtilCtl:removeFile(filePath)
  1517. global.FileUtilCtl:purgeCachedEntries()
  1518. end
  1519. -- check file & remove file
  1520. if global.FileUtilCtl:isFileExist(filePath .. ".tmp") then
  1521. global.FileUtilCtl:removeFile(filePath .. ".tmp")
  1522. global.FileUtilCtl:purgeCachedEntries()
  1523. end
  1524. -- download qrcode
  1525. self.downloader:AsyncDownloadEasy(
  1526. qrcodeURL,
  1527. filePath,
  1528. function(isOK)
  1529. print("download qrcode isOK", isOK)
  1530. HideLoadingBar()
  1531. if false == isOK then
  1532. ShowSystemTips("拉取支付二维码异常 [QRCODE 01]")
  1533. end
  1534. if qrcodeCB then
  1535. qrcodeCB(isOK, filename)
  1536. end
  1537. end,
  1538. 0
  1539. )
  1540. ShowLoadingBar(3)
  1541. -- for debug
  1542. releasePrint("---------------------------------------------- download qrcode")
  1543. releasePrint("url: " .. qrcodeURL)
  1544. end
  1545. function AuthProxy:WriteJuheQRCode(data, qrcodeCB)
  1546. local directoryPath = global.FileUtilCtl:getWritablePath() .. global.L_ModuleManager:GetCurrentModulePath()
  1547. local filename = "qrcode.png"
  1548. local filePath = directoryPath .. filename
  1549. local qrCodeImg = data
  1550. -- remove texture cache
  1551. local textureCache = global.Director:getTextureCache()
  1552. if textureCache:getTextureForKey(filePath) then
  1553. textureCache:removeTextureForKey(filePath)
  1554. end
  1555. -- check directory & create directory
  1556. if not global.FileUtilCtl:isDirectoryExist(directoryPath) then
  1557. global.FileUtilCtl:createDirectory(directoryPath)
  1558. end
  1559. -- check file & remove file
  1560. if global.FileUtilCtl:isFileExist(filePath) then
  1561. global.FileUtilCtl:removeFile(filePath)
  1562. global.FileUtilCtl:purgeCachedEntries()
  1563. end
  1564. local pngBase64Str = string.gsub(qrCodeImg, "data:image/jpg;base64,", "")
  1565. local pngStr = base64dec(pngBase64Str)
  1566. local res = global.FileUtilCtl:writeStringToFile(pngStr, filePath)
  1567. HideLoadingBar()
  1568. if not res then
  1569. ShowSystemTips("生成支付二维码异常 [QRCODE 02]")
  1570. qrcodeCB(false)
  1571. return
  1572. end
  1573. if qrcodeCB then
  1574. qrcodeCB(true, filename)
  1575. end
  1576. end
  1577. function AuthProxy:HTTPRequestPost(url, callback, data, header)
  1578. local httpRequest = cc.XMLHttpRequest:new()
  1579. httpRequest.responseType = cc.XMLHTTPREQUEST_RESPONSE_JSON
  1580. httpRequest.timeout = 100000 -- 10 s
  1581. httpRequest:open("POST", url)
  1582. if header then
  1583. for k, v in pairs(header) do
  1584. httpRequest:setRequestHeader(k, v)
  1585. end
  1586. end
  1587. if callback then
  1588. local function HttpResponseCB()
  1589. local code = httpRequest.status
  1590. local success = code >= 200 and code < 300
  1591. local response = httpRequest.response
  1592. releasePrint("Http Request Code:" .. tostring(code))
  1593. callback(success, response, code)
  1594. end
  1595. httpRequest:registerScriptHandler(HttpResponseCB)
  1596. end
  1597. httpRequest:send(data)
  1598. end
  1599. function AuthProxy:RequestJuhePay(payType, payChannel, productData, qrcodeCB)
  1600. local timeMS = socket.gettime() * 10000
  1601. local trade_no = productData.orderid
  1602. self._orderId = trade_no
  1603. local currencyID = tostring( productData.currencyID )
  1604. local productName = tostring( productData.productName )
  1605. local productPrice = tostring( productData.productPrice )
  1606. local currencyValue = tostring( productData.currencyValue )
  1607. local RechargeProxy = global.Facade:retrieveProxy(global.ProxyTable.RechargeProxy)
  1608. local PlayerProperty = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  1609. local LoginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  1610. local envProxy = global.Facade:retrieveProxy( global.ProxyTable.GameEnvironment )
  1611. local user_name = global.L_GameEnvManager:GetEnvDataByKey("user_name")
  1612. local extUid = global.L_GameEnvManager:GetEnvDataByKey("ext_uid") --未md5加密uid --有小号登录时ext_uid始终传大号id
  1613. local small_user_name = global.L_GameEnvManager:GetEnvDataByKey("small_user_name") --小号name (羽瞬
  1614. local promote_id = global.L_GameEnvManager:GetEnvDataByKey("promote_id")
  1615. local tgt = global.L_GameEnvManager:GetEnvDataByKey("tgt") -- 联想SDK 用户登录返回的 TGT (用户唯一标识)
  1616. local place_id = global.L_GameEnvManager:GetEnvDataByKey("place_id") -- 广告位ID
  1617. local IsSteam = global.L_GameEnvManager:GetEnvDataByKey("IsSteam")
  1618. if IsSteam then
  1619. self._orderId = ""
  1620. trade_no = nil
  1621. end
  1622. local product = RechargeProxy:GetProductByID(productData.currencyID)
  1623. local currencyRatio = product and product.currency_ratio or 1
  1624. local curCoinNum = SL:GetMetaValue("ITEM_COUNT", productData.currencyID) or 0
  1625. -- 下单回调
  1626. -- 下单成功自动下载二维码
  1627. local function orderCB(isOk, qrcodeURL)
  1628. HideLoadingBar()
  1629. if isOk then
  1630. self:DownloadJuheQRCode(qrcodeURL, qrcodeCB)
  1631. else
  1632. qrcodeCB(false)
  1633. end
  1634. end
  1635. -- http数据请求回调
  1636. local function httpCB(success, response)
  1637. releasePrint(response)
  1638. -- request failed
  1639. if not success then
  1640. ShowSystemTips("[-1] 网络异常,请检查网络后重试")
  1641. if orderCB then
  1642. orderCB(false)
  1643. end
  1644. return false
  1645. end
  1646. -- json decode error
  1647. local jsonData = cjson.decode(response)
  1648. dump(jsonData)
  1649. if not jsonData then
  1650. ShowSystemTips("[-2] 拉取支付数据异常")
  1651. if orderCB then
  1652. orderCB(false)
  1653. end
  1654. return false
  1655. end
  1656. -- code error
  1657. if jsonData.status ~= 0 then
  1658. ShowSystemTips(jsonData.status .. " " .. jsonData.msg)
  1659. if orderCB then
  1660. orderCB(false)
  1661. end
  1662. return false
  1663. end
  1664. -- 订单号
  1665. local isPcSdk = global.L_GameEnvManager:GetEnvDataByKey("isPcSdk")
  1666. if jsonData.data and jsonData.data.order_number and isPcSdk then
  1667. productData.PcSdk_orderid = jsonData.data.order_number
  1668. local jsonString = (productData and cjson.encode(productData))
  1669. local methodName = "GN_onCallOF"
  1670. global.NativeBridgeCtl:sendMessage2Native(methodName, jsonString)
  1671. return
  1672. end
  1673. -- 团团SDK
  1674. local base_url = global.L_GameEnvManager:GetEnvDataByKey("baseUrl")
  1675. if jsonData.data and jsonData.data.order_sn and base_url then
  1676. local url = base_url .. "/pay"
  1677. local function httpCB_(success, response)
  1678. releasePrint(response)
  1679. -- request failed
  1680. if not success then
  1681. return false
  1682. end
  1683. end
  1684. local data = {
  1685. {key = "vorderid", value = jsonData.data.order_sn},
  1686. {key = "zone_id", value = LoginProxy:GetSelectedServerId()},
  1687. {key = "zone_name", value = LoginProxy:GetSelectedServerName()},
  1688. {key = "role_id", value = LoginProxy:GetSelectedRoleID()},
  1689. {key = "role_name", value = LoginProxy:GetSelectedRoleName()},
  1690. {key = "role_level", value = PlayerProperty:GetRoleLevel()},
  1691. {key = "fee", value = tonumber(productPrice)},
  1692. {key = "subject", value = productName},
  1693. {key = "body", value = productName},
  1694. }
  1695. local paramData = {}
  1696. for i, v in ipairs(data) do
  1697. paramData[v.key] = v.value
  1698. end
  1699. local suffix = cjson.encode(paramData)
  1700. local header = {}
  1701. header["Content-Type"] = "application/json"
  1702. self:HTTPRequestPost(url, httpCB_, suffix, header)
  1703. releasePrint("POST TT_Url============".. url .. " suffix: ".. suffix)
  1704. return
  1705. end
  1706. -- 直接打开支付界面
  1707. if jsonData.data and jsonData.data.pay_url then
  1708. releasePrint("Pay_Url============", jsonData.data.pay_url )
  1709. cc.Application:getInstance():openURL(jsonData.data.pay_url)
  1710. return
  1711. end
  1712. -- base二维码
  1713. if jsonData.data and jsonData.data.code_img then
  1714. self:WriteJuheQRCode(jsonData.data.code_img, qrcodeCB)
  1715. return
  1716. end
  1717. -- 二维码
  1718. if not jsonData.data.code_img_url then
  1719. ShowSystemTips("[-3] 拉取支付数据异常")
  1720. if orderCB then
  1721. orderCB(false)
  1722. end
  1723. return false
  1724. end
  1725. local IsSteam = global.L_GameEnvManager:GetEnvDataByKey("IsSteam")
  1726. if IsSteam then
  1727. self._orderId = jsonData.data.orderid or ""
  1728. return
  1729. end
  1730. -- 请求支付二维码
  1731. orderCB(true, jsonData.data.code_img_url)
  1732. end
  1733. local doitems =
  1734. {
  1735. [self.PAY_CHANNEL.ALIPAY] = "alipay",
  1736. [self.PAY_CHANNEL.HUABEI] = "alipay",
  1737. [self.PAY_CHANNEL.WEIXIN] = "weixin",
  1738. }
  1739. local ext = {
  1740. ["token"] = self:GetToken(), -- 小号登录时是小号token
  1741. ["game_name"] = self._juhe_param_game_name,
  1742. ["username"] = user_name,
  1743. ["product"] = currencyID,
  1744. ["product_desc"]= productName,
  1745. ["product_ratio"] = tostring(currencyRatio), -- 货币兑换比例
  1746. ["server_name"] = LoginProxy:GetSelectedServerName(),
  1747. ["role_name"] = LoginProxy:GetSelectedRoleName(),
  1748. ["role_level"] = PlayerProperty:GetRoleLevel(),
  1749. ["role_guild"] = PlayerProperty:GetGuildName() or "",
  1750. ["role_coin_num"] = tostring(curCoinNum), -- 玩家当前货币数量
  1751. ["order"] = trade_no,
  1752. -- ["attach"] = 1,
  1753. ["agent_id"] = self._juhe_param_agent_id, --渠道id
  1754. ["coin_id"] = currencyID, --货币id
  1755. ["coins"] = currencyValue, --货币值
  1756. ["small_id"] = self._juhe_small_id,
  1757. ["small_user_name"] = small_user_name,
  1758. ["promote_id"] = promote_id,
  1759. ["yx_extend"] = self._juhe_yx_extend,
  1760. ["place_id"] = place_id,
  1761. }
  1762. local PlayerPropertyProxy = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
  1763. local selSerInfo = LoginProxy:GetSelectedServer()
  1764. ext["job_id"] = PlayerPropertyProxy:GetRoleJob()
  1765. ext["job_name"] = PlayerPropertyProxy:GetRoleJobName() or ""
  1766. ext["main_servid"] = selSerInfo and selSerInfo.mainServerId or ""
  1767. ext["main_server_name"] = selSerInfo and selSerInfo.mainServerName or ""
  1768. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  1769. local prePayDataRePort = DataRePortProxy:PrePay()
  1770. if prePayDataRePort then
  1771. ext["device_info"] = prePayDataRePort
  1772. end
  1773. local extStr = cjson.encode(ext)
  1774. -- dump(extStr)
  1775. local originData = {
  1776. {key="platform", value=envProxy:GetChannelID()},
  1777. {key="cpgameid", value=global.L_ModuleManager:GetCurrentModule():GetOperID()},
  1778. {key="subject", value=self._juhe_param_subject or "dhsf" },
  1779. {key="game_id", value=self._juhe_param_game_id},
  1780. {key="do", value=doitems[payChannel]},
  1781. {key="userid", value= extUid or self:GetUID()}, --Steam平台 user_id直接传的steamID
  1782. {key="server_id", value=LoginProxy:GetSelectedServerId()},
  1783. {key="paymoney", value=productPrice},
  1784. {key="role_id", value=LoginProxy:GetSelectedRoleID()},
  1785. {key="tgt", value=tgt},
  1786. {key = "ext", value= encodeBase64(extStr)},
  1787. {key="original_user_id",value= self._juhe_origin_id},
  1788. }
  1789. --[[ 龙城决
  1790. platform:638
  1791. cpgameid:206
  1792. game_id:26
  1793. ]]
  1794. --[[ 梓轩
  1795. platform:607
  1796. cpgameid:212
  1797. ]]
  1798. --[[ 9377
  1799. platform:561
  1800. cpgameid:194
  1801. game_id : 5431
  1802. subject:dhsf]]
  1803. --[[千贝
  1804. platform:634
  1805. cpgameid:217
  1806. ]]
  1807. --[[顺玩
  1808. platform:1186
  1809. cpgameid:352
  1810. ]]
  1811. --测试数据
  1812. -- local ext = {
  1813. -- ["token"] = "a4e0b47abdeb5768cacfaf5b58fe624b",--global.L_GameEnvManager:GetEnvDataByKey("token"),
  1814. -- ["game_name"] = "顺玩神器",--self._juhe_param_game_name and urlencodeT(self._juhe_param_game_name),
  1815. -- ["username"] = "shtest001",--loginData.username and urlencodeT(loginData.username),
  1816. -- ["product"] = urlencodeT("灵符"),--currencyID,
  1817. -- ["product_desc"]= urlencodeT("灵符"),
  1818. -- ["server_name"] = urlencodeT("区服1"), --LoginProxy:GetSelectedServerName()
  1819. -- ["role_name"] = urlencodeT("角色名称1"), --LoginProxy:GetSelectedRoleName()
  1820. -- ["role_level"] = PlayerProperty:GetRoleLevel(),
  1821. -- ["order"] = "11111",--trade_no,
  1822. -- -- ["attach"] = "1",
  1823. -- ["agent_id"] = 111, --渠道id
  1824. -- ["coin_id"] = currencyID, --货币id
  1825. -- ["coins"] = currencyValue, --货币值
  1826. -- ["small_id"] = "8131",
  1827. -- }
  1828. -- local extStr = cjson.encode(ext)
  1829. -- dump(extStr)
  1830. -- local originData = { --测试数据
  1831. -- {key="platform", value=1928}, --!
  1832. -- {key="cpgameid", value=435}, --!
  1833. -- {key="subject", value="dhsf"}, --!
  1834. -- -- {key="uname", value=urlencodeT("n12345689")}, --!
  1835. -- {key="game_id", value=1},
  1836. -- -- {key="password", value=123456},
  1837. -- {key="do", value= doitems[payChannel]},
  1838. -- {key="userid", value= "juhe_e73387855bebd50"}, --!
  1839. -- {key="server_id", value= 1001}, --!
  1840. -- {key="paymoney", value="1"},
  1841. -- {key="role_id", value="1"}, --!
  1842. -- {key = "ext", value= encodeBase64(extStr)}
  1843. -- }
  1844. -- dump(originData)
  1845. local isQQChannel = global.L_GameEnvManager:GetEnvDataByKey("IsQQ")
  1846. if isQQChannel then
  1847. table.insert(originData, {key="openid", value= global.L_GameEnvManager:GetEnvDataByKey("user_id") }) --
  1848. table.insert(originData, {key="openkey", value= global.L_GameEnvManager:GetEnvDataByKey("token")}) --
  1849. table.insert(originData, {key="pfkey", value= global.L_GameEnvManager:GetEnvDataByKey("pfkey")}) --
  1850. table.insert(originData, {key="appid", value= global.L_GameEnvManager:GetEnvDataByKey("appid")}) --
  1851. table.insert(originData, {key="server_url", value= LoginProxy:GetSelectedServerUrlSuffix()})
  1852. table.insert(originData, {key="role_name", value= LoginProxy:GetSelectedRoleName()})
  1853. table.insert(originData, {key="product", value=currencyID})
  1854. table.insert(originData, {key="product_desc", value=productName})
  1855. -- appid : 1111951543
  1856. local url = domain_qqGame .. juhe_url_qqPay
  1857. local suffix = calcJuheSuffix(originData, juhe_secret_key)
  1858. -- print("pay suffix = ", suffix)
  1859. local function qqPayCallback(success, response)
  1860. -- request failed
  1861. print("qqPayCallback = ", success)
  1862. print("response = ", response)
  1863. if not success then
  1864. ShowSystemTips("网络异常,请检查网络后重试")
  1865. if orderCB then
  1866. orderCB(false)
  1867. end
  1868. return false
  1869. end
  1870. -- json decode error
  1871. local jsonData = cjson.decode(response)
  1872. dump(jsonData)
  1873. if not jsonData then
  1874. ShowSystemTips("拉取支付数据异常")
  1875. if orderCB then
  1876. orderCB(false)
  1877. end
  1878. return false
  1879. end
  1880. if jsonData.ret ~= 0 then
  1881. ShowSystemTips(jsonData.msg or "")
  1882. if orderCB then
  1883. orderCB(false)
  1884. end
  1885. return false
  1886. end
  1887. HideLoadingBar()
  1888. local data = {}
  1889. if jsonData.sandbox then
  1890. data.sandbox = jsonData.sandbox
  1891. end
  1892. if jsonData.url_params then
  1893. data.goodstokenurl = jsonData.url_params
  1894. end
  1895. data.action = "buy"
  1896. data.appid = global.L_GameEnvManager:GetEnvDataByKey("appid")
  1897. data.openid = global.L_GameEnvManager:GetEnvDataByKey("user_id")
  1898. data.openkey = global.L_GameEnvManager:GetEnvDataByKey("token")
  1899. print(cjson.encode(data))
  1900. -- if self:IsQQLauncher() then
  1901. -- if QQBridge then
  1902. -- local param = urlencodeT(cjson.encode(data))
  1903. -- QQBridge:Inst():RequestRecharge(param)
  1904. -- end
  1905. -- else
  1906. local url = "qqgameprotocol:///openembedwebdialog Caption=支付 Width=800 Height=500 New=1 Url=https://qqgame.qq.com/midaspay/?param="
  1907. local param = urlencodeT(cjson.encode(data))
  1908. releasePrint("buyUrl============", url .. param)
  1909. cc.Application:getInstance():openURL(url .. param)
  1910. -- end
  1911. end
  1912. HTTPRequestPost(url, qqPayCallback, suffix)
  1913. -- for debug
  1914. releasePrint("url: " .. url .. " post: " .. suffix)
  1915. else
  1916. local url = juhe_domain..juhe_url_pay
  1917. local suffix = calcJuheSuffix(originData, juhe_secret_key)
  1918. HTTPRequestPost(url, httpCB, suffix)
  1919. -- for debug
  1920. releasePrint("url: " .. url .. " post: " .. suffix)
  1921. end
  1922. ShowLoadingBar(3)
  1923. end
  1924. function AuthProxy:uploadData(data_type, data)
  1925. -- 数据上报
  1926. local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
  1927. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  1928. local selectRole = loginProxy:GetSelectedRole()
  1929. local extUid = global.L_GameEnvManager:GetEnvDataByKey("ext_uid")
  1930. local additional_parameters = data.additional_parameters
  1931. local event_type = data.event_type -- 1.选服 2.创角 3.进游戏 4.升级
  1932. local user_id = extUid or AuthProxy:GetUID()
  1933. local server_id = data.server_id
  1934. local server_name = data.server_name
  1935. local role_id = data.role_id
  1936. local role_name = data.role_name
  1937. local role_level = data.role_level
  1938. local role_create_time = data.role_create_time
  1939. local fight = data.fight
  1940. local role_career = data.role_career
  1941. local role_sex = data.role_sex
  1942. local vip_level = data.vip_level
  1943. local money_num = data.money_num
  1944. local rein_level = data.rein_level
  1945. local PCNeedUpLoad = tonumber(global.ConstantConfig and global.ConstantConfig.PCNeedUpLoadLevel) == 1
  1946. -- 选服不上报
  1947. if data_type == 1 or (not PCNeedUpLoad and data_type == 4) then
  1948. return nil
  1949. end
  1950. -- 团团SDK
  1951. local base_url = global.L_GameEnvManager:GetEnvDataByKey("baseUrl")
  1952. if base_url and string.len(base_url) > 0 then
  1953. local CloseGameID = global.L_GameEnvManager:GetEnvDataByKey("CloseGameID")
  1954. -- 关闭通知
  1955. if data_type == 5 and CloseGameID then
  1956. local url = base_url .. "/close"
  1957. local function httpCB_close(success, response)
  1958. releasePrint(response)
  1959. -- request failed
  1960. if not success then
  1961. return false
  1962. end
  1963. end
  1964. local suffix = cjson.encode({})
  1965. local header = {}
  1966. header["Content-Type"] = "application/json"
  1967. self:HTTPRequestPost(url, httpCB_close, suffix, header)
  1968. releasePrint("POST TT_Url==Close==========".. url .. " suffix: ".. suffix)
  1969. if data and data.gameInitFinish then
  1970. global.userInputController:RequestToOutGame()
  1971. else
  1972. local glview = global.Director:getOpenGLView()
  1973. glview:endToLua()
  1974. end
  1975. return
  1976. end
  1977. local url = base_url .. "/roleReport"
  1978. local function httpCB_(success, response)
  1979. releasePrint(response)
  1980. -- request failed
  1981. if not success then
  1982. return false
  1983. end
  1984. end
  1985. local data = {
  1986. {key = "zone_id", value = server_id},
  1987. {key = "zone_name", value = server_name},
  1988. {key = "role_id", value = role_id},
  1989. {key = "role_name", value = role_name},
  1990. {key = "role_level", value = role_level},
  1991. {key = "shift_level", value = tonumber(rein_level)},
  1992. }
  1993. local paramData = {}
  1994. for i, v in ipairs(data) do
  1995. paramData[v.key] = v.value
  1996. end
  1997. local suffix = cjson.encode(paramData)
  1998. local header = {}
  1999. header["Content-Type"] = "application/json"
  2000. self:HTTPRequestPost(url, httpCB_, suffix, header)
  2001. releasePrint("POST TT_Url==Upload==========".. url .. " suffix: ".. suffix)
  2002. return
  2003. end
  2004. -- http数据请求回调
  2005. local function httpCB(success, response)
  2006. releasePrint(response)
  2007. -- request failed
  2008. if not success then
  2009. return false
  2010. end
  2011. -- json decode error
  2012. local jsonData = cjson.decode(response)
  2013. dump(jsonData)
  2014. if jsonData and jsonData.data and jsonData.data.open_url then
  2015. cc.Application:getInstance():openURL(jsonData.data.open_url)
  2016. releasePrint("UPLOAD_DATA open_url: " .. jsonData.data.open_url)
  2017. local CloseGameID = global.L_GameEnvManager:GetEnvDataByKey("CloseGameID")
  2018. if CloseGameID and data_type == 5 then -- 关闭
  2019. if data and data.gameInitFinish then
  2020. global.userInputController:RequestToOutGame()
  2021. else
  2022. local glview = global.Director:getOpenGLView()
  2023. glview:endToLua()
  2024. end
  2025. end
  2026. end
  2027. end
  2028. local PlayerProperty = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  2029. local LoginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2030. local envProxy = global.Facade:retrieveProxy( global.ProxyTable.GameEnvironment )
  2031. local user_name = global.L_GameEnvManager:GetEnvDataByKey("user_name")
  2032. local promote_id = global.L_GameEnvManager:GetEnvDataByKey("promote_id") -- 推广员ID
  2033. local ext_token = global.L_GameEnvManager:GetEnvDataByKey("ext_token") -- 首次登录token 不是小号登录token
  2034. local small_user_name = global.L_GameEnvManager:GetEnvDataByKey("small_user_name") --小号name (羽瞬
  2035. local place_id = global.L_GameEnvManager:GetEnvDataByKey("place_id") -- 广告位ID
  2036. local originData =
  2037. {
  2038. {key="platform", value=envProxy:GetChannelID()},
  2039. {key="cpgameid", value=global.L_ModuleManager:GetCurrentModule():GetOperID()},
  2040. {key="subject", value=self._juhe_param_subject},
  2041. {key="game_id", value=self._juhe_param_game_id},
  2042. {key="timestamp", value=os.time()},
  2043. {key="data_type", value=data_type},
  2044. {key="additional_parameters", value=additional_parameters},
  2045. {key="event_type", value=event_type},
  2046. {key="user_id", value=user_id},
  2047. {key="user_name", value=user_name},
  2048. {key="server_id", value=server_id},
  2049. {key="server_name", value=server_name},
  2050. {key="role_id", value=role_id},
  2051. {key="role_name", value=role_name},
  2052. {key="role_level", value=role_level},
  2053. {key="role_create_time",value=role_create_time},
  2054. {key="fight", value=fight},
  2055. {key="role_career", value=role_career},
  2056. {key="role_sex", value=role_sex},
  2057. {key="vip_level", value=vip_level},
  2058. {key="money_num", value=money_num},
  2059. {key="log_time", value=os.time()},
  2060. {key="type", value=data_type-1},
  2061. {key="small_id", value=self._juhe_small_id},
  2062. {key="promote_id", value=promote_id},
  2063. {key="token", value=ext_token},
  2064. {key="small_token", value=self:GetToken()},
  2065. {key="small_user_name", value=small_user_name},
  2066. {key="agent_id", value=self._juhe_param_agent_id},
  2067. {key="original_user_id", value= self._juhe_origin_id},
  2068. {key="place_id", value=place_id},
  2069. {key="yx_extend", value= self._juhe_yx_extend}
  2070. }
  2071. local url = juhe_domain..juhe_url_upload
  2072. -- dump(originData)
  2073. -- local originData =
  2074. -- {
  2075. -- {key="platform", value=1186}, --!
  2076. -- {key="cpgameid", value=352},
  2077. -- {key="subject", value="dhsf"},
  2078. -- {key="game_id", value=13},
  2079. -- {key="timestamp", value=os.time()},
  2080. -- {key="data_type", value=data_type},
  2081. -- {key="additional_parameters", value=additional_parameters},
  2082. -- {key="event_type", value=event_type},
  2083. -- {key="user_id", value=8130},
  2084. -- {key="user_name", value="shtest207"},
  2085. -- {key="server_id", value=server_id},
  2086. -- {key="server_name", value=urlencodeT(server_name)},
  2087. -- {key="role_id", value=role_id},
  2088. -- {key="role_name", value=urlencodeT(role_name)},
  2089. -- {key="role_level", value=role_level},
  2090. -- {key="role_create_time",value=role_create_time},
  2091. -- {key="fight", value=fight},
  2092. -- {key="role_career", value=urlencodeT(role_career)},
  2093. -- {key="role_sex", value=role_sex},
  2094. -- {key="vip_level", value=vip_level},
  2095. -- {key="money_num", value=money_num},
  2096. -- {key="log_time", value=os.time()},
  2097. -- {key="type", value=data_type-1},
  2098. -- {key="small_id", value=8131},--self._juhe_small_id},
  2099. -- }
  2100. local suffix = calcJuheSuffix(originData, juhe_secret_key ,true)
  2101. HTTPRequestPost(url, httpCB, suffix)
  2102. -- for debug
  2103. releasePrint("---------------------------------------------- upload")
  2104. releasePrint("url: " .. url .. " post: " .. suffix)
  2105. end
  2106. -- QQ大厅数据上报
  2107. function AuthProxy:uploadDataQQGame(data_type,data)
  2108. local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
  2109. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2110. local selectRole = loginProxy:GetSelectedRole()
  2111. local data_type = data_type -- 1.选服 2.创角 3.进游戏 4.升级 5.QQ登录时机 6.QQ注册时机(伪)
  2112. local user_id = data.user_id or AuthProxy:GetUID()
  2113. local server_id = data.server_id
  2114. local server_name = data.server_name
  2115. local role_id = data.role_id
  2116. local role_name = data.role_name
  2117. local role_level = data.role_level
  2118. -- local role_create_time = data.role_create_time
  2119. local role_career = data.role_career
  2120. local role_sex = data.role_sex
  2121. -- 选服不上报
  2122. if data_type == 1 or data_type == 4 then
  2123. return nil
  2124. end
  2125. -- http数据请求回调
  2126. local function httpCB(success, response)
  2127. releasePrint(response)
  2128. -- request failed
  2129. if not success then
  2130. print("[-1] 网络异常,请求上报QQ数据失败.")
  2131. return false
  2132. end
  2133. -- json decode error
  2134. local jsonData = cjson.decode(response)
  2135. dump(jsonData)
  2136. end
  2137. local PlayerProperty = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  2138. local LoginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2139. local envProxy = global.Facade:retrieveProxy( global.ProxyTable.GameEnvironment )
  2140. local user_name = global.L_GameEnvManager:GetEnvDataByKey("user_name")
  2141. local originData =
  2142. {
  2143. {key="platform", value=envProxy:GetChannelID()},
  2144. {key="cpgameid", value=global.L_ModuleManager:GetCurrentModule():GetOperID()},
  2145. {key="subject", value=self._juhe_param_subject},
  2146. {key="game_id", value=self._juhe_param_game_id},
  2147. {key="timestamp", value=os.time()},
  2148. {key="data_type", value=data_type},
  2149. {key="user_id", value=user_id},
  2150. -- {key="user_name", value=user_name},
  2151. {key="server_id", value=server_id},
  2152. {key="server_name", value=server_name},
  2153. {key="role_id", value=role_id},
  2154. {key="role_name", value=role_name},
  2155. {key="role_level", value=role_level},
  2156. -- {key="role_create_time",value=role_create_time},
  2157. {key="role_career", value=role_career},
  2158. {key="role_sex", value=role_sex},
  2159. {key="log_time", value=os.time()},
  2160. }
  2161. local url = domain_qqGame .. juhe_url_qqUpload
  2162. local suffix = calcJuheSuffix(originData, "webgame@2019J5v6ByRT" ,true) --无签名验证
  2163. HTTPRequestPost(url, httpCB, suffix)
  2164. -- for debug
  2165. releasePrint("---------------------------------------------- QQ upload")
  2166. releasePrint("url: " .. url .. " post: " .. suffix)
  2167. end
  2168. function AuthProxy:uploadBoxData(data_type, data)
  2169. if not data_type or data_type ~= 2 then -- 创角
  2170. return
  2171. end
  2172. local isBoxAD = global.L_GameEnvManager:GetEnvDataByKey("isBoxAD")
  2173. local roomid = global.L_GameEnvManager:GetEnvDataByKey("roomid")
  2174. local url = nil
  2175. if isBoxAD and tonumber(isBoxAD) == 1 then -- 广告
  2176. url = domain_box .. url_roleAD
  2177. elseif roomid and tonumber(roomid) == 3 then -- 新游推荐
  2178. url = domain_boxN .. url_roleNewRecom
  2179. else
  2180. return
  2181. end
  2182. if not url then return end
  2183. local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
  2184. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2185. local selectRole = loginProxy:GetSelectedRole()
  2186. local user_id = AuthProxy:GetUID()
  2187. local server_id = data.server_id
  2188. local role_id = data.role_id
  2189. local role_name = data.role_name
  2190. local function httpCB(success, response)
  2191. releasePrint(response)
  2192. -- request failed
  2193. if not success then
  2194. print("[-1] 网络异常,请求上报盒子创角数据失败.")
  2195. return false
  2196. end
  2197. -- json decode error
  2198. local jsonData = cjson.decode(response)
  2199. dump(jsonData)
  2200. end
  2201. local PlayerProperty = global.Facade:retrieveProxy( global.ProxyTable.PlayerProperty )
  2202. local envProxy = global.Facade:retrieveProxy( global.ProxyTable.GameEnvironment )
  2203. local listId = global.L_GameEnvManager:GetEnvDataByKey("open_game_list_id") or 0 -- 盒子 开服列表ID
  2204. local originData =
  2205. {
  2206. {key="user_id", value=user_id},
  2207. {key="game_id", value=global.L_ModuleManager:GetCurrentModule():GetOperID()},
  2208. {key="open_game_list_id", value=listId},
  2209. {key="server_id", value=server_id},
  2210. {key="roleid", value=role_id},
  2211. {key="rolename", value=role_name},
  2212. }
  2213. local suffix = calcJuheSuffix(originData, signBoxKey , nil, true)
  2214. HTTPRequestPost(url, httpCB, suffix)
  2215. -- for debug
  2216. releasePrint("---------------------------------------------- Box upload")
  2217. releasePrint("url: " .. url .. " post: " .. suffix)
  2218. end
  2219. function AuthProxy:IsQQChannel()
  2220. local isQQChannel = global.L_GameEnvManager:GetEnvDataByKey("IsQQ")
  2221. return isQQChannel
  2222. end
  2223. function AuthProxy:RequestWordFilteringQQ(contentType, content, callbackCB, ex_param)
  2224. local isback = false
  2225. if ex_param and ex_param.replacedWords and next(ex_param.replacedWords) then
  2226. ex_param.status = 1 -- 被隐藏
  2227. else
  2228. if not ex_param then
  2229. ex_param = {}
  2230. end
  2231. ex_param.status = 0 -- 无标记
  2232. end
  2233. -- 请求失败/超时 默认禁止
  2234. local impassableBan = SL:GetMetaValue("GAME_DATA", "ReviewImpassableBan") == 1
  2235. local function scheduleCB()
  2236. if not isback then
  2237. isback = true
  2238. if callbackCB then
  2239. if impassableBan then
  2240. callbackCB(false, false)
  2241. else
  2242. callbackCB(true, content, nil, ex_param)
  2243. end
  2244. end
  2245. end
  2246. end
  2247. -- 团团SDK特殊自己审核
  2248. local base_url = global.L_GameEnvManager:GetEnvDataByKey("baseUrl")
  2249. local isTTReview = tonumber(global.L_GameEnvManager:GetEnvDataByKey("isTTReview")) == 1
  2250. if base_url and string.len(base_url) > 0 and isTTReview then
  2251. local url = base_url .. "/message"
  2252. local function httpCB(success, response)
  2253. if isback then return end
  2254. releasePrint(response)
  2255. isback = true
  2256. -- request failed
  2257. if not success then --默认合法
  2258. if callbackCB then
  2259. callbackCB(true, content, nil, ex_param)
  2260. end
  2261. return false
  2262. end
  2263. local jsonData = cjson.decode(response)
  2264. dump(jsonData)
  2265. if not jsonData or type(jsonData) ~= "table" then
  2266. if callbackCB then
  2267. callbackCB(true, content, nil, ex_param)
  2268. end
  2269. return false
  2270. end
  2271. if jsonData.data then
  2272. local data = jsonData.data
  2273. local result = data.result
  2274. local text = data.text
  2275. if result and text then -- 安锋
  2276. -- result 1合法 2部分合法 3完全不合法
  2277. if tonumber(result) ~= 1 and (tonumber(contentType) == 1 or tonumber(contentType) == 3) then -- 昵称/公告拒绝
  2278. if callbackCB then
  2279. callbackCB(false, false)
  2280. end
  2281. return true
  2282. else
  2283. if callbackCB then
  2284. if (result - 1) == 2 then
  2285. -- 2: 静默 3: 静默+被隐藏
  2286. ex_param.status = ex_param.status == 1 and 3 or 2
  2287. end
  2288. callbackCB(true, text, result - 1, ex_param)
  2289. end
  2290. return true
  2291. end
  2292. end
  2293. end
  2294. --无结果默认通过
  2295. if callbackCB then
  2296. callbackCB(true, content, nil, ex_param)
  2297. end
  2298. end
  2299. local suffix = cjson.encode({
  2300. text = content,
  2301. scene = contentType, --
  2302. })
  2303. local header = {}
  2304. header["Content-Type"] = "application/json"
  2305. self:HTTPRequestPost(url, httpCB, suffix, header)
  2306. releasePrint("POST TT_Url==Review==========".. url .. " suffix: ".. suffix)
  2307. return
  2308. end
  2309. -- http数据请求回调
  2310. local function httpCB(success, response)
  2311. if isback then return end
  2312. releasePrint(response)
  2313. isback = true
  2314. if not success then --默认合法
  2315. if callbackCB then
  2316. if impassableBan then
  2317. callbackCB(false, false)
  2318. else
  2319. callbackCB(true, content, nil, ex_param)
  2320. end
  2321. end
  2322. return false
  2323. end
  2324. -- json decode error
  2325. local jsonData = cjson.decode(response)
  2326. dump(jsonData)
  2327. if not jsonData or type(jsonData) ~= "table" then
  2328. if callbackCB then
  2329. callbackCB(true, content, nil, ex_param)
  2330. end
  2331. return false
  2332. end
  2333. -- code error
  2334. if jsonData.status ~= 0 then
  2335. releasePrint("--word_Filter_error: "..jsonData.status .. " " .. jsonData.msg)
  2336. if callbackCB then
  2337. callbackCB(true, content, nil, ex_param)
  2338. end
  2339. return false
  2340. end
  2341. if jsonData.data then
  2342. local qqData = jsonData.data
  2343. if qqData.text_result_list_ then
  2344. local result = qqData.text_result_list_[1]
  2345. if result.check_ret_ == 0 then --合法
  2346. if callbackCB then
  2347. callbackCB(true, content, nil, ex_param)
  2348. end
  2349. return true
  2350. elseif result.check_ret_ == 1 then --恶意
  2351. if result.punish_type_ == 1 then --禁止
  2352. if callbackCB then
  2353. callbackCB(false, false)
  2354. end
  2355. return true
  2356. elseif result.punish_type_ == 2 then --可过滤
  2357. if callbackCB then
  2358. callbackCB(false, result.result_text_, nil, ex_param)
  2359. end
  2360. return true
  2361. end
  2362. end
  2363. elseif jsonData.data.suggestion then -- AI
  2364. if jsonData.data.suggestion == "pass" then
  2365. if callbackCB then
  2366. callbackCB(true, content, nil, ex_param)
  2367. end
  2368. return true
  2369. elseif jsonData.data.suggestion == "review" or jsonData.data.suggestion == "block" then
  2370. if callbackCB then
  2371. callbackCB(false, false)
  2372. end
  2373. return true
  2374. end
  2375. elseif jsonData.data.level then -- 小7/易盾 检查结果
  2376. if tonumber(jsonData.data.level) == 1 then
  2377. if callbackCB then
  2378. callbackCB(true, content, nil, ex_param)
  2379. end
  2380. return true
  2381. elseif tonumber(jsonData.data.level) == -1 then
  2382. if callbackCB then
  2383. callbackCB(false, false)
  2384. end
  2385. return true
  2386. end
  2387. elseif jsonData.data.yd996_status and jsonData.data.str then -- 网易/易盾
  2388. -- yd996_status 0通过 1疑问 2拒绝
  2389. if tonumber(jsonData.data.yd996_status) ~= 0 and ( tonumber(contentType) == 1 or tonumber(contentType) == 3 ) then -- 昵称/公告拒绝
  2390. if callbackCB then
  2391. callbackCB(false, false)
  2392. end
  2393. return true
  2394. else
  2395. if callbackCB then
  2396. if jsonData.data.sensitive_word and jsonData.data.sensitive_word ~= "" and type(jsonData.data.sensitive_word) == "table" then
  2397. local replacedWords = ex_param and ex_param.replacedWords or {}
  2398. for i, word in ipairs(jsonData.data.sensitive_word) do
  2399. if word and string.len(word) > 0 then
  2400. table.insert(replacedWords, word)
  2401. end
  2402. end
  2403. ex_param.replacedWords = replacedWords
  2404. end
  2405. if tonumber(jsonData.data.yd996_status) == 2 then
  2406. -- 2: 静默 3: 静默+被隐藏
  2407. ex_param.status = ex_param.status == 1 and 3 or 2
  2408. end
  2409. callbackCB(true, jsonData.data.str, tonumber(jsonData.data.yd996_status), ex_param)
  2410. end
  2411. return true
  2412. end
  2413. end
  2414. end
  2415. --无结果默认通过
  2416. if callbackCB then
  2417. callbackCB(true, content, nil, ex_param)
  2418. end
  2419. end
  2420. local envProxy = global.Facade:retrieveProxy( global.ProxyTable.GameEnvironment )
  2421. local isQQChannel = global.L_GameEnvManager:GetEnvDataByKey("IsQQ")
  2422. local loginProxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
  2423. local role_id = loginProxy:GetSelectedRoleID()
  2424. local role_name = loginProxy:GetSelectedRoleName()
  2425. local server_id = loginProxy:GetSelectedServerId()
  2426. local AuthProxy = global.Facade:retrieveProxy( global.ProxyTable.AuthProxy )
  2427. local user_id = AuthProxy:GetUID()
  2428. local serverName = loginProxy:GetSelectedServerName()
  2429. local currentModule = global.L_ModuleManager:GetCurrentModule()
  2430. local gameName = currentModule:GetName()
  2431. local area = nil
  2432. if gameName and serverName then
  2433. area = string.format( "%s_%s", gameName, serverName )
  2434. end
  2435. local CONTENT_TYPE = { --支持“chat”(聊天消息),“nick”(昵称),"post"(帖 子),"notice"(公告), "signature"(签名)5种
  2436. "nick","chat","notice","post","signature"
  2437. }
  2438. local ServerTimeProxy = global.Facade:retrieveProxy(global.ProxyTable.ServerTimeProxy)
  2439. local openDay = 0
  2440. local openTime = nil
  2441. if ServerTimeProxy and ServerTimeProxy.GetOpenDay then
  2442. openDay = ServerTimeProxy:GetOpenDay()
  2443. openTime = ServerTimeProxy:GetOpenTime()
  2444. end
  2445. local platform = 0
  2446. if cc.PLATFORM_OS_ANDROID == global.Platform or global.isOHOS then
  2447. platform = 1
  2448. elseif cc.PLATFORM_OS_IPAD == global.Platform or cc.PLATFORM_OS_IPHONE == global.Platform then
  2449. platform = 2
  2450. end
  2451. local player = global.gamePlayerController and global.gamePlayerController:GetMainPlayer()
  2452. local role_level = nil
  2453. if player then
  2454. role_level = player:GetLevel()
  2455. end
  2456. local ext = {
  2457. ["user_id"] = user_id, --角色所属小号id (小7的就是uid)
  2458. ["device_type"] = platform, --设备类型:1=安卓 2=ios
  2459. }
  2460. local extStr = cjson.encode(ext)
  2461. local originData = {
  2462. {key = "str", value = content},
  2463. {key = "type", value = contentType},
  2464. {key ="platform", value = envProxy:GetChannelID()},
  2465. {key ="cpgameid", value = global.L_ModuleManager:GetCurrentModule():GetOperID()},
  2466. {key ="subject", value = self._juhe_param_subject or "dhsf"},
  2467. {key ="context_type", value= CONTENT_TYPE[tonumber(contentType)]},
  2468. {key ="user_id", value= user_id},
  2469. {key ="username", value= self._username},
  2470. {key ="role_id", value= role_id},
  2471. {key ="role_name", value= role_name},
  2472. {key ="role_level", value= role_level},
  2473. {key ="server_id", value= server_id},
  2474. {key ="area", value= area},
  2475. {key ="open_day", value= openDay},
  2476. {key ="open_time", value= openTime},
  2477. {key ="ext", value= encodeBase64(extStr)}
  2478. }
  2479. if isQQChannel then
  2480. table.insert(originData, {key="openid", value= global.L_GameEnvManager:GetEnvDataByKey("user_id") }) --
  2481. table.insert(originData, {key="openkey", value= global.L_GameEnvManager:GetEnvDataByKey("token")}) --
  2482. table.insert(originData, {key="pfkey", value= global.L_GameEnvManager:GetEnvDataByKey("pfkey")}) --
  2483. table.insert(originData, {key="appid", value= global.L_GameEnvManager:GetEnvDataByKey("appid")}) --
  2484. end
  2485. if ex_param and next(ex_param) then
  2486. for k, val in pairs(ex_param) do
  2487. if k ~= "replacedWords" and k ~= "originStr" then
  2488. table.insert(originData, {key = k, value = val})
  2489. end
  2490. end
  2491. end
  2492. local url = domain_qqGame .. juhe_url_qqFilter
  2493. local suffix = calcJuheSuffix(originData, juhe_secret_key)
  2494. HTTPRequestPost(url, httpCB, suffix)
  2495. PerformWithDelayGlobal(scheduleCB, 3)
  2496. -- for debug
  2497. releasePrint("------------------------------------------WordFiltering++")
  2498. releasePrint("url: " .. url .. " post: " .. suffix)
  2499. end
  2500. function AuthProxy:RequestQQDawankaInfo( ... )
  2501. local isQQChannel = global.L_GameEnvManager:GetEnvDataByKey("IsTTQQ") or global.L_GameEnvManager:GetEnvDataByKey("IsQQ")
  2502. if isQQChannel then
  2503. local requestData = {}
  2504. requestData["openid"] = global.L_GameEnvManager:GetEnvDataByKey("qqgame_openid") or global.L_GameEnvManager:GetEnvDataByKey("user_id")
  2505. requestData["openkey"] = global.L_GameEnvManager:GetEnvDataByKey("qqgame_openkey") or global.L_GameEnvManager:GetEnvDataByKey("token")
  2506. requestData["appkey"] = global.L_GameEnvManager:GetEnvDataByKey("qqgame_appkey") or global.L_GameEnvManager:GetEnvDataByKey("appkey") or "9GMF2HknSZeJZgzb"
  2507. requestData["appid"] = global.L_GameEnvManager:GetEnvDataByKey("qqgame_appid") or global.L_GameEnvManager:GetEnvDataByKey("appid")
  2508. local userData = UserData:new("QQDAWAKA_data")
  2509. local dawakaData = userData:getStringForKey("data", nil)
  2510. if dawakaData and string.len(dawakaData) > 0 then
  2511. requestData["dawakaData"] = dawakaData
  2512. end
  2513. local sendStr = cjson.encode( requestData )
  2514. LuaSendMsg(global.MsgType.MSG_CS_GET_DAWANKA_INFO, 0, 0, 0, 0, sendStr, string.len(sendStr))
  2515. end
  2516. end
  2517. function AuthProxy:RequestDecodeJWTToServer( ... )
  2518. local xlData = global.L_GameEnvManager:GetEnvDataByKey("xlData")
  2519. local decodeJwt = nil
  2520. if xlData and string.len(xlData) > 0 then
  2521. LuaSendMsg(global.MsgType.MSG_CS_SEND_XULEI_VIP, 0, 0, 0, 0, xlData, string.len(xlData))
  2522. end
  2523. end
  2524. function AuthProxy:calcCloudSignSuffix(originData, secret_key, unlencode)
  2525. table.sort(originData, function(a, b)
  2526. return a.key < b.key
  2527. end)
  2528. -- 拼接
  2529. local origin = ""
  2530. local valueStr = ""
  2531. for i, v in ipairs(originData) do
  2532. if v and v.key and v.value and string.len(v.key) > 0 and string.len(v.value) > 0 then
  2533. if unlencode then
  2534. origin = origin .. string.format("%s=%s", v.key, urlencodeT(v.value))
  2535. else
  2536. origin = origin .. string.format("%s=%s", v.key, v.value)
  2537. end
  2538. origin = origin .. "&"
  2539. valueStr = valueStr .. v.value
  2540. end
  2541. end
  2542. origin = string.sub(origin, 1, string.len(origin)-1)
  2543. local rqtime = os.time()
  2544. local rqrandom = randDataID("Box")
  2545. valueStr = valueStr .. secret_key .. rqtime .. rqrandom
  2546. origin = origin.."&rqtime="..rqtime.."&rqrandom="..rqrandom
  2547. releasePrint("isCloudLogin : RequestIsCloudLogin "..valueStr)
  2548. local signMD5 = get_str_MD5(valueStr)
  2549. -- local suffix = origin .. "&" .. string.format("sign=%s", signMD5)
  2550. local oTab = {}
  2551. for k,v in pairs(originData) do
  2552. if not unlencode and v and v.unlencode == true then
  2553. oTab[v.key] = v.value
  2554. else
  2555. oTab[v.key] = urlencodeT(v.value)
  2556. end
  2557. end
  2558. oTab.rqtime = rqtime
  2559. oTab.rqrandom = rqrandom
  2560. oTab.sign = signMD5
  2561. return oTab
  2562. end
  2563. --直播红包+飘屏群 上报需求
  2564. function AuthProxy:RequestUpLoadCreateRole(jsonData)
  2565. local action = "/trilateral/v1/create/role/task"
  2566. -- cloud_box_url = "https://test-api.996box.com"
  2567. local url = cloud_box_url .. action
  2568. local currModule = global.L_ModuleManager:GetCurrentModule()
  2569. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2570. local mainServerId = loginProxy:GetMainSelectedServerId()
  2571. local promoteId = global.L_GameEnvManager:GetGMName()
  2572. local envProxy = global.Facade:retrieveProxy(global.ProxyTable.GameEnvironment)
  2573. local platformid = envProxy:GetChannelID()
  2574. local roles = loginProxy:GetRoles() or {}
  2575. local roleNum = math.max(1, #roles)
  2576. local originData = {
  2577. {key="exp", value = 0},
  2578. {key="gameId", value = tonumber(currModule:GetOperID())},
  2579. {key="job", value = tonumber(jsonData.roleJobId)},
  2580. {key="mainServerId", value = tonumber(mainServerId)},
  2581. {key="occurredTime", value = tonumber(jsonData.roleCTime)},
  2582. {key="onlineTime", value = 0},
  2583. {key="platformId", value = tostring(platformid)},
  2584. {key="reLevel", value = 0},
  2585. {key="roleId", value = jsonData.roleId},
  2586. {key="roleLevel", value = tonumber(jsonData.roleLevel)},
  2587. {key="roleName", value = jsonData.roleName},
  2588. {key="serverId", value = tonumber(jsonData.zoneId)},
  2589. {key="serverName", value = jsonData.zoneName},
  2590. {key="userId", value = jsonData.userId},
  2591. {key="roleNum", value = roleNum},
  2592. {key="promoteId", value = promoteId},
  2593. }
  2594. -- dump(url,"url___")
  2595. local suffix = self:calcCloudSignSuffix(originData, boxSceneSignKey)
  2596. -- dump(suffix,"suffix___")
  2597. local header = {}
  2598. header["Content-Type"] = "application/json"
  2599. function MyHTTPRequestPost(url, callback, data, header)
  2600. local httpRequest = cc.XMLHttpRequest:new()
  2601. httpRequest.responseType = cc.XMLHTTPREQUEST_RESPONSE_JSON
  2602. httpRequest.timeout = 100000 -- 10 s
  2603. httpRequest:open("POST", url)
  2604. if header then
  2605. for k, v in pairs(header) do
  2606. httpRequest:setRequestHeader(k, v)
  2607. end
  2608. end
  2609. if callback then
  2610. local function HttpResponseCB()
  2611. local code = httpRequest.status
  2612. local success = code >= 200 and code < 300
  2613. local response = httpRequest.response
  2614. release_print("Http Request Code:" .. tostring(code))
  2615. callback(success, response, code)
  2616. end
  2617. httpRequest:registerScriptHandler(HttpResponseCB)
  2618. end
  2619. httpRequest:send(data)
  2620. end
  2621. MyHTTPRequestPost(url, function (success, response)
  2622. dump({success, response},"RequestUpLoadCreateRole_______")
  2623. if success then
  2624. end
  2625. end, cjson.encode(suffix), header)
  2626. releasePrint("**** createRole url: ", url)
  2627. end
  2628. function AuthProxy:RequestIsCloudLogin()
  2629. --云真机启动 上报服务器
  2630. if global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
  2631. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2632. local user_id = self:GetUID()
  2633. local server_id = loginProxy:GetSelectedServerId()
  2634. local role_id = loginProxy:GetSelectedRoleID()
  2635. local userPhoneId = global.L_GameEnvManager:GetEnvDataByKey("userPhoneId") or ""
  2636. local packName = global.L_GameEnvManager:GetAPKPackageName() or ""
  2637. local role_name = loginProxy:GetSelectedRoleName()
  2638. local originData =
  2639. {
  2640. {key="extUserDeviceNo", value=userPhoneId},
  2641. {key="gameRegionId", value=server_id},
  2642. {key="gameRoleId", value=role_id},
  2643. {key="uid", value=user_id},
  2644. {key="gameRoleName", value=role_name},
  2645. }
  2646. local suffixTab = self:calcCloudSignSuffix(originData, boxSceneSignKey)
  2647. local data = {}
  2648. data.url = cloud_box_url .. cloud_record_url
  2649. data.ojson = cjson.encode(suffixTab)
  2650. global.L_NativeBridgeManager:GN_sendCloudLoginMes(data)
  2651. local sendStr = packName.. "#" ..userPhoneId
  2652. releasePrint("PackageName:"..sendStr)
  2653. if packName ~= "" then
  2654. LuaSendMsg(global.MsgType.MSG_CS_YWPACKINFO_REQUEST, 0, 0, 0, 0, sendStr, string.len(sendStr))
  2655. end
  2656. end
  2657. end
  2658. -- 云机货币检测列表
  2659. function AuthProxy:RequestCloudMoneyCheckList()
  2660. -- 货币列表
  2661. if global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
  2662. --cloud_check_money_list
  2663. local baseURL = cloud_box_url
  2664. -- baseURL = "https://test-api.996box.com"
  2665. local currModule = global.L_ModuleManager:GetCurrentModule()
  2666. local originData =
  2667. {
  2668. {key="gameId", value=tostring(currModule:GetOperID())},
  2669. }
  2670. local suffixTabStr = calcBoxSignSuffix(originData, boxSceneSignKey)
  2671. local url = string.format("%s%s?%s", baseURL, cloud_check_money_list, suffixTabStr)
  2672. HTTPRequest(url, function(success, response)
  2673. -- body
  2674. releasePrint("===response: ", response)
  2675. if not success then
  2676. releasePrint("查询云机货币列表请求失败")
  2677. return false
  2678. end
  2679. local jsonData = cjson.decode(response)
  2680. if not jsonData then
  2681. releasePrint("查询云机货币列表解析失败")
  2682. return false
  2683. end
  2684. if not jsonData.data then
  2685. releasePrint("云机货币列表未配置")
  2686. return false
  2687. end
  2688. local DataRePortProxy = global.Facade:retrieveProxy(global.ProxyTable.DataRePortProxy)
  2689. DataRePortProxy:SetCloundCheckMoneyList(jsonData.data.currencyId)
  2690. end)
  2691. releasePrint("===云机货币列表url: ", url)
  2692. end
  2693. end
  2694. -- 上报云机货币
  2695. function AuthProxy:RequestCloudMoney( moneyList )
  2696. -- 云真机货币 上报服务器
  2697. if global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
  2698. local AutoProxy = global.Facade:retrieveProxy( global.ProxyTable.Auto )
  2699. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2700. local user_id = self:GetUID()
  2701. local role_id = loginProxy:GetSelectedRoleID()
  2702. local afkState = AutoProxy:IsAFKState() and 1 or 0
  2703. local originData =
  2704. {
  2705. {key="currencyStatusList", value=moneyList, unlencode = true},
  2706. {key="hangUpStatus", value=afkState},
  2707. {key="roleId", value=role_id},
  2708. {key="userId", value=user_id},
  2709. }
  2710. local suffixTab = self:calcCloudSignSuffix(originData, boxSceneSignKey)
  2711. local data = {}
  2712. data.url = cloud_money_url .. cloud_money_list_url
  2713. data.ojson = cjson.encode(suffixTab)
  2714. releasePrint("======cloud money: ", data.ojson)
  2715. global.L_NativeBridgeManager:GN_sendCloudLoginMes(data)
  2716. end
  2717. end
  2718. function AuthProxy:CloudOtherLogin()
  2719. --云真机顶号 上报服务器
  2720. if global.L_GameEnvManager:GetEnvDataByKey("isCloudLogin") then
  2721. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2722. local user_id = self:GetUID()
  2723. local server_id = loginProxy:GetSelectedServerId()
  2724. local role_id = loginProxy:GetSelectedRoleID()
  2725. local userPhoneId = global.L_GameEnvManager:GetEnvDataByKey("userPhoneId") or ""
  2726. local originData =
  2727. {
  2728. {key="extUserDeviceNo", value=userPhoneId},
  2729. {key="gameRegionId", value=server_id},
  2730. {key="gameRoleId", value=role_id},
  2731. {key="uid", value=user_id},
  2732. }
  2733. local suffixTab = self:calcCloudSignSuffix(originData, boxSceneSignKey)
  2734. local url = cloud_box_url .. cloud_otherlogin
  2735. dump(url,"url____")
  2736. local ojson = cjson.encode(suffixTab)
  2737. local header = {}
  2738. header["Content-Type"] = "application/json"
  2739. function MyHTTPRequestPost(url, callback, data, header)
  2740. local httpRequest = cc.XMLHttpRequest:new()
  2741. httpRequest.responseType = cc.XMLHTTPREQUEST_RESPONSE_JSON
  2742. httpRequest.timeout = 100000 -- 10 s
  2743. httpRequest:open("POST", url)
  2744. if header then
  2745. for k, v in pairs(header) do
  2746. httpRequest:setRequestHeader(k, v)
  2747. end
  2748. end
  2749. if callback then
  2750. local function HttpResponseCB()
  2751. local code = httpRequest.status
  2752. local success = code >= 200 and code < 300
  2753. local response = httpRequest.response
  2754. release_print("Http Request Code:" .. tostring(code))
  2755. callback(success, response, code)
  2756. end
  2757. httpRequest:registerScriptHandler(HttpResponseCB)
  2758. end
  2759. httpRequest:send(data)
  2760. end
  2761. MyHTTPRequestPost(url,function(success, response, code)
  2762. releasePrint("CloudOtherLogin")
  2763. releasePrint(response)
  2764. releasePrint(code)
  2765. end, ojson, header)
  2766. end
  2767. end
  2768. local function calcTecentSuffix(originData, secret_key, uri)
  2769. -- ascii排序
  2770. table.sort(originData, function(a, b)
  2771. return a.key < b.key
  2772. end)
  2773. -- 拼接
  2774. local origin = ""
  2775. for i, v in ipairs(originData) do
  2776. if v and v.key and v.value and string.len(v.key) > 0 and string.len(v.value) > 0 then
  2777. origin = origin .. string.format("%s=%s", v.key, v.value)
  2778. origin = origin .. "&"
  2779. end
  2780. end
  2781. origin = string.sub(origin, 1, string.len(origin)-1)
  2782. -- URL编码
  2783. local urlUri = urlencodeT(uri)
  2784. local urlStr = "POST&" .. urlUri .. "&"..urlencodeT(origin)
  2785. -- HMAC-SHA1
  2786. local sign = sha1.hmac_binary(secret_key, urlStr)
  2787. -- Base64
  2788. sign = encodeBase64(sign)
  2789. --
  2790. local suffix = origin .. "&" .. string.format("sig=%s", urlencodeT(sign))
  2791. return suffix
  2792. end
  2793. -- QQ大厅续期openKey
  2794. function AuthProxy:RequestRenewalQQOpenKey(islogin)
  2795. local QQ_renewal_uri = "/v3/user/is_login"
  2796. local isQQChannel = global.L_GameEnvManager:GetEnvDataByKey("IsQQ")
  2797. if isQQChannel then
  2798. local date = os.date("*t", GetServerTime())
  2799. local nextHourMin = 60 - date.min
  2800. local delayTime = nextHourMin == 0 and 0.1 or nextHourMin*60
  2801. PerformWithDelayGlobal(function ( ... )
  2802. local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
  2803. if AuthProxy then
  2804. self._canRenewal = true
  2805. AuthProxy:RequestRenewalQQOpenKey()
  2806. end
  2807. end, delayTime)
  2808. end
  2809. if isQQChannel and (self._canRenewal or islogin) then
  2810. local function httpCB(success, response)
  2811. releasePrint(response)
  2812. if success then
  2813. local jsonData = cjson.decode(response)
  2814. if islogin and jsonData and jsonData.ret and jsonData.ret ~= 0 then
  2815. local errorcode = jsonData.ret
  2816. local errorMsg = jsonData.msg
  2817. ShowSystemTips("登录态校验失败! 请重新从QQ大厅启动游戏. ["..errorcode .. "] ".. errorMsg)
  2818. end
  2819. dump(jsonData)
  2820. end
  2821. end
  2822. local originData = {
  2823. {key="openid", value= global.L_GameEnvManager:GetEnvDataByKey("user_id")},
  2824. {key="openkey", value= global.L_GameEnvManager:GetEnvDataByKey("token")},
  2825. {key="appid", value= global.L_GameEnvManager:GetEnvDataByKey("appid")},
  2826. {key="pf", value= "qqgame"},
  2827. {key="format", value= "json"}
  2828. }
  2829. local appkey = global.L_GameEnvManager:GetEnvDataByKey("appkey")
  2830. local url = host_tencent..QQ_renewal_uri
  2831. local suffix = calcTecentSuffix(originData, appkey.."&", QQ_renewal_uri)
  2832. HTTPRequestPost(url, httpCB, suffix)
  2833. releasePrint("RenewalQQOpenKey url: " .. url .. " post: " .. suffix)
  2834. end
  2835. end
  2836. function AuthProxy:RequestModeInfoCheck()
  2837. if global.isDebugMode or global.isGMMode then
  2838. return nil
  2839. end
  2840. local checkURLs = global.L_GameEnvManager:GetEnvDataByKey("modlist") or ""
  2841. local planBURL = global.L_GameEnvManager:GetEnvDataByKey("modlistPlanB")
  2842. if planBURL and string.len(planBURL) > 0 then
  2843. checkURLs = checkURLs .. "," .. planBURL
  2844. end
  2845. local url = string.format("%s%s?type=%s&host=%s", mode_info_check, mode_info_interface, "c2", checkURLs)
  2846. HTTPRequest(url, function( success, response )
  2847. -- body
  2848. if not success then
  2849. PerformWithDelayGlobal(function()
  2850. self:RequestModeInfoCheck()
  2851. end, 5 * 60)
  2852. end
  2853. success = true
  2854. if response and string.len(response) > 0 then
  2855. local jsonData = cjson.decode(response)
  2856. if jsonData and jsonData.data == 0 then
  2857. success = false
  2858. end
  2859. end
  2860. releasePrint("======CHECK: ", response or "")
  2861. if not success then
  2862. local function callback(bType, custom)
  2863. if bType == 1 then
  2864. if global.isWindows then
  2865. global.Director:endToLua()
  2866. else
  2867. global.L_NativeBridgeManager:GN_accountLogout()
  2868. global.Facade:sendNotification( global.NoticeTable.RestartGame )
  2869. end
  2870. end
  2871. end
  2872. local data = {}
  2873. data.str = GET_STRING(1048) .. "[CHECK]"
  2874. data.btnDesc = { GET_STRING(1026)}
  2875. data.callback = callback
  2876. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  2877. end
  2878. end)
  2879. end
  2880. -- 发送雷电VIP等级到后台
  2881. function AuthProxy:RequestVIPLevel()
  2882. if vip_domain and string.len(vip_domain) > 0 then
  2883. local isHave, levelData = SL:GetMetaValue("VIP_LEVEL")
  2884. if not isHave then
  2885. release_print("不存在vip等级数据")
  2886. return
  2887. end
  2888. local url = vip_domain .. vip_upload_url
  2889. local currModule = global.L_ModuleManager:GetCurrentModule()
  2890. local loginProxy = global.Facade:retrieveProxy( global.ProxyTable.Login )
  2891. local selectRole = loginProxy:GetSelectedRoleID()
  2892. local zoneId = loginProxy:GetSelectedServerId()
  2893. local time = os.time()
  2894. local inParam = cjson.encode({plus = 0, channel = levelData.channel, vip = levelData.level})
  2895. local originData = {
  2896. {key="game_appid", value = ""},
  2897. {key="channal", value = ""},
  2898. {key="channel_uid", value = ""},
  2899. {key="in_param", value = inParam, unlencode = true},
  2900. {key="user_id", value = ""},
  2901. {key="token", value = ""},
  2902. {key="p", value = ""},
  2903. {key="time", value = time},
  2904. }
  2905. local sign = self:sign(originData, "4a2a624deaa6adaf7751425f7d5f8087")
  2906. local baseUrl = string.format("%s?channal=&channel_uid=&gameid=%s&game_appid=&in_param=%s&p=&role_id=%s&server_id=%s&sign=%s&time=%s&token=&user_id=", url, tostring(currModule:GetOperID()), urlencodeT(inParam), tostring(selectRole), tostring(zoneId), sign, tostring(time))
  2907. release_print("vipurl", baseUrl)
  2908. HTTPRequest(baseUrl, function(success, response)
  2909. -- body
  2910. releasePrint("===response====: ", response)
  2911. end)
  2912. end
  2913. end
  2914. function AuthProxy:sign(originData, secret_key, unlencode)
  2915. table.sort(originData, function(a, b)
  2916. return a.key < b.key
  2917. end)
  2918. -- 拼接
  2919. local origin = ""
  2920. for i, v in ipairs(originData) do
  2921. -- if v and v.key and v.value and string.len(v.key) > 0 and string.len(v.value) > 0 then
  2922. if unlencode then
  2923. origin = origin .. string.format("%s=%s", v.key, urlencodeT(v.value))
  2924. else
  2925. origin = origin .. string.format("%s=%s", v.key, v.value)
  2926. end
  2927. origin = origin .. "&"
  2928. -- end
  2929. end
  2930. origin = string.sub(origin, 1, string.len(origin)-1)
  2931. releasePrint("isCloudLogin : RequestIsCloudLogin " .. origin..secret_key)
  2932. local signMD5 = get_str_MD5(origin..secret_key)
  2933. -- local suffix = origin .. "&" .. string.format("sign=%s", signMD5)
  2934. local oTab = {}
  2935. for k,v in pairs(originData) do
  2936. if not unlencode and v and v.unlencode == true then
  2937. oTab[v.key] = v.value
  2938. else
  2939. oTab[v.key] = urlencodeT(v.value)
  2940. end
  2941. end
  2942. return signMD5
  2943. end
  2944. return AuthProxy