config.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. }
  67. // Android 产品包的配置数据
  68. var Android = {
  69. editor : template.std, // 测试渠道
  70. }
  71. // iOS 产品包的配置数据
  72. var IOS = {
  73. yudha : template.yudha,
  74. yuda_abd : template.yuda_abd,
  75. yuda_abdof : template.yuda_abd,
  76. }
  77. //谷歌的验证密钥
  78. var GooglePlay_SIG = {
  79. // 'com.mgames.pixel.en' : {
  80. // sig : 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5XPAAyaVLvvp5tleB2lpDgsDBOOt3Jly/HycNJGGAZe/80niCLe1Tdu6OVzjHCjm4KDxQvcHGUxjbKZK53nsR+zLG1oahk+uBG99BBhnqm3QuYQYoBZs0zj56qqyCkz0r8Nj/TenwBLliYiA4i/z/LIPL+71Z7NBamxH1GqK1JL+E/gNdwI6r0lnEqFqfGqmB/hVP5jQa6ogxxY27f0lD7+p1QV7sDQfIzSGX+M49Notf10Ptesr0BNr6IkMFdQHZRPjdHJBmGAaBw4tAKk/HcyLH22NDexpSU2YOeyr4aMrQ89ydIHGO7KlgPel5Uag/h+ERHv12PrEE2pYrp0qCQIDAQAB',
  81. // },
  82. // 'com.jl3rd.zlwx.google' : { // yytx_dny
  83. // sig : 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApHXWDxtD66vELk6/Xdz0G4CiKKZLfjCauJ1wqDuAxbx2K1jX8YZ56XfyS594sGtBapVpmweLWT6/YrKXpoRv0OXUCL1TFdFaD0S7F6Fvocxcwjq6VHUxd3d7X9ye0yyURDNdqo2phGZbo2HnAF8kzA2ohSNer3ZTLUqqj53Tv0lUjIEWYo5eI/N/F24xRHy5q1JTm+cuRczuUqN5Gh+gt8qAPYPRNTHTNg4WRjGq097ONLnvjzisjubUQiDaYOj1wbPyHYPypAltX0PVt1JnTQ1H/JlFgOUAjATipm41r9CQ2tZVuB98xetVwYpQLK6tS3HztnDmbN0XbhEFEUL+KwIDAQAB'
  84. // },
  85. }
  86. // IOS 中是否是沙盒测试的istest=1沙盒测试 2:正式
  87. var IOS_ISTEST = {
  88. // zd_ios: {istest : 1,},
  89. }
  90. /*
  91. channel: 渠道名
  92. istest: google 使用 (IOS 使用 IOS_ISTEST)
  93. 通过包名,查找对于的渠道标识
  94. */
  95. var appid_channel = {
  96. // "com.jl3rd.zlwx.google":{channel:"yytx_dny",istest:1 }, // yytx_dny(公司发行东南亚) //1是测试2是正式
  97. }
  98. // 通过 cifd 反向查找配置
  99. exports.reverse = function(platform, channel, cfid) {
  100. platform = platform ? platform.toLowerCase() : 'null'
  101. channel = channel ? channel.toLowerCase() : "null"
  102. cfid = cfid ? cfid : 'null'
  103. var hash = null;
  104. if (platform == "ios") {
  105. hash = IOS;
  106. } else if (platform == 'android') {
  107. hash = Android;
  108. } else if (platform == 'zayaweb') {
  109. hash = Web;
  110. }
  111. if (hash) {
  112. var option = hash[channel]
  113. if (option) {
  114. for (var key in option) {
  115. var ret = option[key];
  116. if (ret.cfid == cfid) {
  117. return ret
  118. }
  119. }
  120. }
  121. }
  122. return { cfid:0, typename:'', price:0, diamond:0 }
  123. }
  124. // 解析(在google/ios设置的档位名称) xxx.xxx.1001 返回最后的数据
  125. exports.parse_end = function(key){
  126. var a = key.split('.');
  127. var len = a.length;
  128. if (len > 0) {
  129. key = parseInt(a[len-1]);
  130. if(!key){
  131. key = a[len-1];
  132. }
  133. }
  134. return key
  135. }
  136. exports.parse = function(platform,channel,key) {
  137. platform = platform ? platform.toLowerCase() : 'null'
  138. channel = channel ? channel.toLowerCase() : "null"
  139. key = key ? key : 'null'
  140. var hash = null;
  141. if (platform == 'ios') {
  142. if (key) {
  143. var a = key.split('.');
  144. var len = a.length;
  145. if (len > 0) {
  146. key = parseInt(a[len-1]);
  147. if(!key){
  148. key = a[len-1];
  149. }
  150. hash = IOS;
  151. }
  152. }
  153. } else if (platform == 'android') {
  154. key = parseInt(key);
  155. hash = Android;
  156. } else if(platform == 'googleplay'){
  157. if (key) {
  158. var a = key.split('.');
  159. var len = a.length;
  160. if (len > 0) {
  161. key = parseInt(a[len-1]);
  162. if(!key){
  163. key = a[len-1];
  164. }
  165. hash = Android;
  166. if(hash.editor && hash.editor[key]){
  167. return hash.editor[key]
  168. }
  169. }
  170. }
  171. } else if(platform == "web"){
  172. key = parseInt(key);
  173. hash = Web;
  174. }
  175. if (hash) {
  176. var option = hash[channel];
  177. if (option && option[key]) {
  178. return option[key]
  179. }
  180. }
  181. return { cfid:0, typename:'', price:0, diamond:0 }
  182. }
  183. //@TODO: 是否存在该渠道
  184. exports.allowed_ios_channel = function(channel) {
  185. var option = IOS[channel];
  186. return option ? true : false
  187. }
  188. //@TODO: 充值模式获取
  189. exports.get_ios_istest = function(channel){
  190. var option = IOS_ISTEST[channel];
  191. console.log("option.istest:%s",option.istest)
  192. if (option && (option.istest || 0 == option.istest)){
  193. return option.istest
  194. }
  195. return 2
  196. }
  197. //@TODO: 是否是安卓的充值
  198. exports.allowed_android_channel = function(channel) {
  199. var option = Android[channel];
  200. return option ? true : false
  201. }
  202. //@TODO: google充值秘钥
  203. exports.get_googleplay_sig = function(channel){
  204. var option = GooglePlay_SIG[channel];
  205. if (option && option.sig){
  206. return option.sig
  207. }
  208. return 2
  209. }
  210. // 配置 TalkingData 的 AppID
  211. exports.getAppID = function(channel) {
  212. if (channel=="yudha"){
  213. return "0FE175A24C984525AD76DBE6A46031A0"; // 屠龙简体
  214. }
  215. else if(channel == 'yuda_abd'){
  216. return "91BF1908F5554C0E8DF31C2F9B180A3E"; // 屠龙港澳台
  217. }
  218. else if(channel == 'yuda_abdof'){
  219. return "0645B126AF3642A8AF8A510BF657BA64"; // 屠龙港澳台3测
  220. }
  221. else {
  222. return null;
  223. }
  224. }
  225. // google 通过包名获取渠道配置
  226. exports.get_channel = function(open_appid){
  227. if (appid_channel[open_appid]){
  228. return appid_channel[open_appid].channel;
  229. }
  230. }
  231. // 获取 是否测试标识
  232. exports.get_istest = function(open_appid) {
  233. // console.log("####get_istest %s", open_appid)
  234. if (appid_channel[open_appid]){
  235. return appid_channel[open_appid].istest;
  236. }
  237. return 3
  238. }
  239. // 卓动 是否验证 md5(小游戏使用)
  240. exports.get_verify = function(open_appid) {
  241. if (appid_channel[open_appid]){
  242. return appid_channel[open_appid].verify;
  243. }
  244. return false;
  245. }
  246. //@TODO: 将传入的 data数据, 拼接在一起
  247. exports.url_sort = function(data){
  248. var sort_data = Object.keys(data).sort();
  249. // 生成本地签名验证签名
  250. var strsign = data[sort_data[0]];
  251. for(var i=1;i<sort_data.length;i++){
  252. if(sort_data[i] != "sign"){
  253. strsign = strsign + '&'+ data[sort_data[i]]
  254. }
  255. }
  256. return strsign
  257. }