config.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. function str2asc(strstr){
  2. return ("0"+strstr.charCodeAt(0).toString(16)).slice(-2);
  3. }
  4. function asc2str(ascasc){
  5. return String.fromCharCode(ascasc);
  6. }
  7. exports.UrlEncode=function(str){
  8. var ret="";
  9. var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
  10. var tt= "";
  11. for(var i=0;i<str.length;i++){
  12. var chr = str.charAt(i);
  13. var c=str2asc(chr);
  14. tt += chr+":"+c+"n";
  15. if(parseInt("0x"+c) > 0x7f){
  16. ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
  17. }else{
  18. if(chr==" ")
  19. ret+="+";
  20. else if(strSpecial.indexOf(chr)!=-1)
  21. ret+="%"+c.toString(16);
  22. else
  23. ret+=chr;
  24. }
  25. }
  26. return ret;
  27. }
  28. exports.UrlDecode = function(str){
  29. var ret="";
  30. for(var i=0;i<str.length;i++){
  31. var chr = str.charAt(i);
  32. if(chr == "+"){
  33. ret+=" ";
  34. }else if(chr=="%"){
  35. var asc = str.substring(i+1,i+3);
  36. if(parseInt("0x"+asc)>0x7f){
  37. ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
  38. i+=5;
  39. }else{
  40. ret+=asc2str(parseInt("0x"+asc));
  41. i+=2;
  42. }
  43. }else{
  44. ret+= chr;
  45. }
  46. }
  47. return ret;
  48. }
  49. var template = {
  50. std : {
  51. '20001': { cfid:20001, typename:'USD', price:.19, name:'1元档位'},
  52. '20002': { cfid:20002, typename:'USD', price:.45, name:'3元档位'},
  53. '20003': { cfid:20003, typename:'USD', price:.99, name:'6元档位'},
  54. '20004': { cfid:20004, typename:'USD', price:.99, name:'8元档位'},
  55. '20005': { cfid:20005, typename:'USD', price:1.99, name:'12元档位'},
  56. '20006': { cfid:20006, typename:'USD', price:2.99, name:'18元档位'},
  57. '20007': { cfid:20007, typename:'USD', price:4.99, name:'30元档位'},
  58. '20008': { cfid:20008, typename:'USD', price:10.99, name:'68元档位'},
  59. '20009': { cfid:20009, typename:'USD', price:14.99, name:'98元档位'},
  60. '20010': { cfid:20010, typename:'USD', price:19.99, name:'128元档位'},
  61. '20011': { cfid:20011, typename:'USD', price:29.99, name:'198元档位'},
  62. '20012': { cfid:20012, typename:'USD', price:49.99, name:'328元档位'},
  63. '20013': { cfid:20013, typename:'USD', price:74.99, name:'488元档位'},
  64. '20014': { cfid:20014, typename:'USD', price:99.99, name:'648元档位'},
  65. },
  66. CNY : {
  67. '20001': { cfid:20001, typename:'CNY', price:1, name:'1元档位'},
  68. '20002': { cfid:20002, typename:'CNY', price:3, name:'3元档位'},
  69. '20003': { cfid:20003, typename:'CNY', price:6, name:'6元档位'},
  70. '20004': { cfid:20004, typename:'CNY', price:8, name:'8元档位'},
  71. '20005': { cfid:20005, typename:'CNY', price:12, name:'12元档位'},
  72. '20006': { cfid:20006, typename:'CNY', price:18, name:'18元档位'},
  73. '20007': { cfid:20007, typename:'CNY', price:30, name:'30元档位'},
  74. '20008': { cfid:20008, typename:'CNY', price:68, name:'68元档位'},
  75. '20009': { cfid:20009, typename:'CNY', price:98, name:'98元档位'},
  76. '20010': { cfid:20010, typename:'CNY', price:128, name:'128元档位'},
  77. '20011': { cfid:20011, typename:'CNY', price:198, name:'198元档位'},
  78. '20012': { cfid:20012, typename:'CNY', price:328, name:'328元档位'},
  79. '20013': { cfid:20013, typename:'CNY', price:488, name:'488元档位'},
  80. '20014': { cfid:20014, typename:'CNY', price:648, name:'648元档位'},
  81. },
  82. USD : {
  83. '20001': { cfid:20001, typename:'USD', price:.19, name:'1元档位'},
  84. '20002': { cfid:20002, typename:'USD', price:.45, name:'3元档位'},
  85. '20003': { cfid:20003, typename:'USD', price:.99, name:'6元档位'},
  86. '20004': { cfid:20004, typename:'USD', price:.99, name:'8元档位'},
  87. '20005': { cfid:20005, typename:'USD', price:1.99, name:'12元档位'},
  88. '20006': { cfid:20006, typename:'USD', price:2.99, name:'18元档位'},
  89. '20007': { cfid:20007, typename:'USD', price:4.99, name:'30元档位'},
  90. '20008': { cfid:20008, typename:'USD', price:10.99, name:'68元档位'},
  91. '20009': { cfid:20009, typename:'USD', price:14.99, name:'98元档位'},
  92. '20010': { cfid:20010, typename:'USD', price:19.99, name:'128元档位'},
  93. '20011': { cfid:20011, typename:'USD', price:29.99, name:'198元档位'},
  94. '20012': { cfid:20012, typename:'USD', price:49.99, name:'328元档位'},
  95. '20013': { cfid:20013, typename:'USD', price:74.99, name:'488元档位'},
  96. '20014': { cfid:20014, typename:'USD', price:99.99, name:'648元档位'},
  97. },
  98. HKD : {
  99. '20001': { cfid:20001, typename:'HKD', price:3, name:'1元档位'},
  100. '20002': { cfid:20002, typename:'HKD', price:6, name:'3元档位'},
  101. '20003': { cfid:20003, typename:'HKD', price:8, name:'6元档位'},
  102. '20004': { cfid:20004, typename:'HKD', price:10, name:'8元档位'},
  103. '20005': { cfid:20005, typename:'HKD', price:15, name:'12元档位'},
  104. '20006': { cfid:20006, typename:'HKD', price:23, name:'18元档位'},
  105. '20007': { cfid:20007, typename:'HKD', price:38, name:'30元档位'},
  106. '20008': { cfid:20008, typename:'HKD', price:78, name:'68元档位'},
  107. '20009': { cfid:20009, typename:'HKD', price:118, name:'98元档位'},
  108. '20010': { cfid:20010, typename:'HKD', price:158, name:'128元档位'},
  109. '20011': { cfid:20011, typename:'HKD', price:239, name:'198元档位'},
  110. '20012': { cfid:20012, typename:'HKD', price:389, name:'328元档位'},
  111. '20013': { cfid:20013, typename:'HKD', price:589, name:'488元档位'},
  112. '20014': { cfid:20014, typename:'HKD', price:779, name:'648元档位'},
  113. },
  114. TWD : {
  115. '20001': { cfid:20001, typename:'TWD', price:10, name:'1元档位'},
  116. '20002': { cfid:20002, typename:'TWD', price:20, name:'3元档位'},
  117. '20003': { cfid:20003, typename:'TWD', price:33, name:'6元档位'},
  118. '20004': { cfid:20004, typename:'TWD', price:45, name:'8元档位'},
  119. '20005': { cfid:20005, typename:'TWD', price:65, name:'12元档位'},
  120. '20006': { cfid:20006, typename:'TWD', price:100, name:'18元档位'},
  121. '20007': { cfid:20007, typename:'TWD', price:170, name:'30元档位'},
  122. '20008': { cfid:20008, typename:'TWD', price:330, name:'68元档位'},
  123. '20009': { cfid:20009, typename:'TWD', price:490, name:'98元档位'},
  124. '20010': { cfid:20010, typename:'TWD', price:640, name:'128元档位'},
  125. '20011': { cfid:20011, typename:'TWD', price:990, name:'198元档位'},
  126. '20012': { cfid:20012, typename:'TWD', price:1690, name:'328元档位'},
  127. '20013': { cfid:20013, typename:'TWD', price:2450, name:'488元档位'},
  128. '20014': { cfid:20014, typename:'TWD', price:3290, name:'648元档位'},
  129. },
  130. }
  131. // Android 产品包的配置数据
  132. var Android = {
  133. editor : template.std, // 测试渠道
  134. shengtiancny : template.CNY, // 圣天
  135. shengtianhkd : template.HKD, // 圣天
  136. shengtiantwd : template.TWD, // 圣天
  137. shengtianusd : template.USD, // 圣天
  138. }
  139. // iOS 产品包的配置数据
  140. var IOS = {
  141. yudha : template.yudha,
  142. yuda_abd : template.yuda_abd,
  143. yuda_abdof : template.yuda_abd,
  144. }
  145. //谷歌的验证密钥
  146. var GooglePlay_SIG = {
  147. // 'com.mgames.pixel.en' : {
  148. // sig : 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5XPAAyaVLvvp5tleB2lpDgsDBOOt3Jly/HycNJGGAZe/80niCLe1Tdu6OVzjHCjm4KDxQvcHGUxjbKZK53nsR+zLG1oahk+uBG99BBhnqm3QuYQYoBZs0zj56qqyCkz0r8Nj/TenwBLliYiA4i/z/LIPL+71Z7NBamxH1GqK1JL+E/gNdwI6r0lnEqFqfGqmB/hVP5jQa6ogxxY27f0lD7+p1QV7sDQfIzSGX+M49Notf10Ptesr0BNr6IkMFdQHZRPjdHJBmGAaBw4tAKk/HcyLH22NDexpSU2YOeyr4aMrQ89ydIHGO7KlgPel5Uag/h+ERHv12PrEE2pYrp0qCQIDAQAB',
  149. // },
  150. // 'com.jl3rd.zlwx.google' : { // yytx_dny
  151. // sig : 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApHXWDxtD66vELk6/Xdz0G4CiKKZLfjCauJ1wqDuAxbx2K1jX8YZ56XfyS594sGtBapVpmweLWT6/YrKXpoRv0OXUCL1TFdFaD0S7F6Fvocxcwjq6VHUxd3d7X9ye0yyURDNdqo2phGZbo2HnAF8kzA2ohSNer3ZTLUqqj53Tv0lUjIEWYo5eI/N/F24xRHy5q1JTm+cuRczuUqN5Gh+gt8qAPYPRNTHTNg4WRjGq097ONLnvjzisjubUQiDaYOj1wbPyHYPypAltX0PVt1JnTQ1H/JlFgOUAjATipm41r9CQ2tZVuB98xetVwYpQLK6tS3HztnDmbN0XbhEFEUL+KwIDAQAB'
  152. // },
  153. }
  154. // IOS 中是否是沙盒测试的istest=1沙盒测试 2:正式
  155. var IOS_ISTEST = {
  156. // zd_ios: {istest : 1,},
  157. }
  158. /*
  159. channel: 渠道名
  160. istest: google 使用 (IOS 使用 IOS_ISTEST)
  161. 通过包名,查找对于的渠道标识
  162. */
  163. var appid_channel = {
  164. // "com.jl3rd.zlwx.google":{channel:"yytx_dny",istest:1 }, // yytx_dny(公司发行东南亚) //1是测试2是正式
  165. }
  166. // 通过 cifd 反向查找配置
  167. exports.reverse = function(platform, channel, cfid) {
  168. platform = platform ? platform.toLowerCase() : 'null'
  169. channel = channel ? channel.toLowerCase() : "null"
  170. cfid = cfid ? cfid : 'null'
  171. var hash = null;
  172. if (platform == "ios") {
  173. hash = IOS;
  174. } else if (platform == 'android') {
  175. hash = Android;
  176. } else if (platform == 'zayaweb') {
  177. hash = Web;
  178. }
  179. if (hash) {
  180. var option = hash[channel]
  181. if (option) {
  182. for (var key in option) {
  183. var ret = option[key];
  184. if (ret.cfid == cfid) {
  185. return ret
  186. }
  187. }
  188. }
  189. }
  190. return { cfid:0, typename:'', price:0, diamond:0 }
  191. }
  192. // 解析(在google/ios设置的档位名称) xxx.xxx.1001 返回最后的数据
  193. exports.parse_end = function(key){
  194. var a = key.split('.');
  195. var len = a.length;
  196. if (len > 0) {
  197. key = parseInt(a[len-1]);
  198. if(!key){
  199. key = a[len-1];
  200. }
  201. }
  202. return key
  203. }
  204. exports.parse = function(platform,channel,key) {
  205. platform = platform ? platform.toLowerCase() : 'null'
  206. channel = channel ? channel.toLowerCase() : "null"
  207. console.log(channel)
  208. key = key ? key : 'null'
  209. var hash = null;
  210. if (platform == 'ios') {
  211. if (key) {
  212. var a = key.split('.');
  213. var len = a.length;
  214. if (len > 0) {
  215. key = parseInt(a[len-1]);
  216. if(!key){
  217. key = a[len-1];
  218. }
  219. hash = IOS;
  220. }
  221. }
  222. } else if (platform == 'android') {
  223. key = parseInt(key);
  224. hash = Android;
  225. } else if(platform == 'googleplay'){
  226. if (key) {
  227. var a = key.split('.');
  228. var len = a.length;
  229. if (len > 0) {
  230. key = parseInt(a[len-1]);
  231. if(!key){
  232. key = a[len-1];
  233. }
  234. hash = Android;
  235. if(hash.editor && hash.editor[key]){
  236. return hash.editor[key]
  237. }
  238. }
  239. }
  240. } else if(platform == "web"){
  241. key = parseInt(key);
  242. hash = Web;
  243. }
  244. if (hash) {
  245. var option = hash[channel];
  246. if (option && option[key]) {
  247. return option[key]
  248. }
  249. }
  250. return { cfid:0, typename:'', price:0, diamond:0 }
  251. }
  252. //@TODO: 是否存在该渠道
  253. exports.allowed_ios_channel = function(channel) {
  254. var option = IOS[channel];
  255. return option ? true : false
  256. }
  257. //@TODO: 充值模式获取
  258. exports.get_ios_istest = function(channel){
  259. var option = IOS_ISTEST[channel];
  260. console.log("option.istest:%s",option.istest)
  261. if (option && (option.istest || 0 == option.istest)){
  262. return option.istest
  263. }
  264. return 2
  265. }
  266. //@TODO: 是否是安卓的充值
  267. exports.allowed_android_channel = function(channel) {
  268. var option = Android[channel];
  269. return option ? true : false
  270. }
  271. //@TODO: google充值秘钥
  272. exports.get_googleplay_sig = function(channel){
  273. var option = GooglePlay_SIG[channel];
  274. if (option && option.sig){
  275. return option.sig
  276. }
  277. return 2
  278. }
  279. // 配置 TalkingData 的 AppID
  280. exports.getAppID = function(channel) {
  281. if (channel=="yudha"){
  282. return "0FE175A24C984525AD76DBE6A46031A0"; // 屠龙简体
  283. }
  284. else if(channel == 'yuda_abd'){
  285. return "91BF1908F5554C0E8DF31C2F9B180A3E"; // 屠龙港澳台
  286. }
  287. else if(channel == 'yuda_abdof'){
  288. return "0645B126AF3642A8AF8A510BF657BA64"; // 屠龙港澳台3测
  289. }
  290. else {
  291. return null;
  292. }
  293. }
  294. // google 通过包名获取渠道配置
  295. exports.get_channel = function(open_appid){
  296. if (appid_channel[open_appid]){
  297. return appid_channel[open_appid].channel;
  298. }
  299. }
  300. // 获取 是否测试标识
  301. exports.get_istest = function(open_appid) {
  302. // console.log("####get_istest %s", open_appid)
  303. if (appid_channel[open_appid]){
  304. return appid_channel[open_appid].istest;
  305. }
  306. return 3
  307. }
  308. // 卓动 是否验证 md5(小游戏使用)
  309. exports.get_verify = function(open_appid) {
  310. if (appid_channel[open_appid]){
  311. return appid_channel[open_appid].verify;
  312. }
  313. return false;
  314. }
  315. //@TODO: 将传入的 data数据, 拼接在一起
  316. exports.url_sort = function(data){
  317. var sort_data = Object.keys(data).sort();
  318. // 生成本地签名验证签名
  319. var strsign = data[sort_data[0]];
  320. for(var i=1;i<sort_data.length;i++){
  321. if(sort_data[i] != "sign"){
  322. strsign = strsign + '&'+ data[sort_data[i]]
  323. }
  324. }
  325. return strsign
  326. }
  327. exports.url_sort2 = function(data){
  328. var sort_data = Object.keys(data).sort();
  329. // 生成本地签名验证签名
  330. var strsign = sort_data[0]+'='+data[sort_data[0]];
  331. for(var i=1;i<sort_data.length;i++){
  332. if(sort_data[i] != "sign"){
  333. strsign = strsign + '&'+ sort_data[i] + '=' + data[sort_data[i]]
  334. }
  335. }
  336. return strsign
  337. }