123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- function str2asc(strstr){
- return ("0"+strstr.charCodeAt(0).toString(16)).slice(-2);
- }
- function asc2str(ascasc){
- return String.fromCharCode(ascasc);
- }
- exports.UrlEncode=function(str){
- var ret="";
- var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
- var tt= "";
- for(var i=0;i<str.length;i++){
- var chr = str.charAt(i);
- var c=str2asc(chr);
- tt += chr+":"+c+"n";
- if(parseInt("0x"+c) > 0x7f){
- ret+="%"+c.slice(0,2)+"%"+c.slice(-2);
- }else{
- if(chr==" ")
- ret+="+";
- else if(strSpecial.indexOf(chr)!=-1)
- ret+="%"+c.toString(16);
- else
- ret+=chr;
- }
- }
- return ret;
- }
- exports.UrlDecode = function(str){
- var ret="";
- for(var i=0;i<str.length;i++){
- var chr = str.charAt(i);
- if(chr == "+"){
- ret+=" ";
- }else if(chr=="%"){
- var asc = str.substring(i+1,i+3);
- if(parseInt("0x"+asc)>0x7f){
- ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6)));
- i+=5;
- }else{
- ret+=asc2str(parseInt("0x"+asc));
- i+=2;
- }
- }else{
- ret+= chr;
- }
- }
- return ret;
- }
- var template = {
- std : {
- '20001': { cfid:20001, typename:'USD', price:.19, name:'1元档位'},
- '20002': { cfid:20002, typename:'USD', price:.45, name:'3元档位'},
- '20003': { cfid:20003, typename:'USD', price:.99, name:'6元档位'},
- '20004': { cfid:20004, typename:'USD', price:.99, name:'8元档位'},
- '20005': { cfid:20005, typename:'USD', price:1.99, name:'12元档位'},
- '20006': { cfid:20006, typename:'USD', price:2.99, name:'18元档位'},
- '20007': { cfid:20007, typename:'USD', price:4.99, name:'30元档位'},
- '20008': { cfid:20008, typename:'USD', price:10.99, name:'68元档位'},
- '20009': { cfid:20009, typename:'USD', price:14.99, name:'98元档位'},
- '20010': { cfid:20010, typename:'USD', price:19.99, name:'128元档位'},
- '20011': { cfid:20011, typename:'USD', price:29.99, name:'198元档位'},
- '20012': { cfid:20012, typename:'USD', price:49.99, name:'328元档位'},
- '20013': { cfid:20013, typename:'USD', price:74.99, name:'488元档位'},
- '20014': { cfid:20014, typename:'USD', price:99.99, name:'648元档位'},
- },
-
- CNY : {
- '20001': { cfid:20001, typename:'CNY', price:1, name:'1元档位'},
- '20002': { cfid:20002, typename:'CNY', price:3, name:'3元档位'},
- '20003': { cfid:20003, typename:'CNY', price:6, name:'6元档位'},
- '20004': { cfid:20004, typename:'CNY', price:8, name:'8元档位'},
- '20005': { cfid:20005, typename:'CNY', price:12, name:'12元档位'},
- '20006': { cfid:20006, typename:'CNY', price:18, name:'18元档位'},
- '20007': { cfid:20007, typename:'CNY', price:30, name:'30元档位'},
- '20008': { cfid:20008, typename:'CNY', price:68, name:'68元档位'},
- '20009': { cfid:20009, typename:'CNY', price:98, name:'98元档位'},
- '20010': { cfid:20010, typename:'CNY', price:128, name:'128元档位'},
- '20011': { cfid:20011, typename:'CNY', price:198, name:'198元档位'},
- '20012': { cfid:20012, typename:'CNY', price:328, name:'328元档位'},
- '20013': { cfid:20013, typename:'CNY', price:488, name:'488元档位'},
- '20014': { cfid:20014, typename:'CNY', price:648, name:'648元档位'},
- },
- USD : {
- '20001': { cfid:20001, typename:'USD', price:.19, name:'1元档位'},
- '20002': { cfid:20002, typename:'USD', price:.45, name:'3元档位'},
- '20003': { cfid:20003, typename:'USD', price:.99, name:'6元档位'},
- '20004': { cfid:20004, typename:'USD', price:.99, name:'8元档位'},
- '20005': { cfid:20005, typename:'USD', price:1.99, name:'12元档位'},
- '20006': { cfid:20006, typename:'USD', price:2.99, name:'18元档位'},
- '20007': { cfid:20007, typename:'USD', price:4.99, name:'30元档位'},
- '20008': { cfid:20008, typename:'USD', price:10.99, name:'68元档位'},
- '20009': { cfid:20009, typename:'USD', price:14.99, name:'98元档位'},
- '20010': { cfid:20010, typename:'USD', price:19.99, name:'128元档位'},
- '20011': { cfid:20011, typename:'USD', price:29.99, name:'198元档位'},
- '20012': { cfid:20012, typename:'USD', price:49.99, name:'328元档位'},
- '20013': { cfid:20013, typename:'USD', price:74.99, name:'488元档位'},
- '20014': { cfid:20014, typename:'USD', price:99.99, name:'648元档位'},
- },
- HKD : {
- '20001': { cfid:20001, typename:'HKD', price:3, name:'1元档位'},
- '20002': { cfid:20002, typename:'HKD', price:6, name:'3元档位'},
- '20003': { cfid:20003, typename:'HKD', price:8, name:'6元档位'},
- '20004': { cfid:20004, typename:'HKD', price:10, name:'8元档位'},
- '20005': { cfid:20005, typename:'HKD', price:15, name:'12元档位'},
- '20006': { cfid:20006, typename:'HKD', price:23, name:'18元档位'},
- '20007': { cfid:20007, typename:'HKD', price:38, name:'30元档位'},
- '20008': { cfid:20008, typename:'HKD', price:78, name:'68元档位'},
- '20009': { cfid:20009, typename:'HKD', price:118, name:'98元档位'},
- '20010': { cfid:20010, typename:'HKD', price:158, name:'128元档位'},
- '20011': { cfid:20011, typename:'HKD', price:239, name:'198元档位'},
- '20012': { cfid:20012, typename:'HKD', price:389, name:'328元档位'},
- '20013': { cfid:20013, typename:'HKD', price:589, name:'488元档位'},
- '20014': { cfid:20014, typename:'HKD', price:779, name:'648元档位'},
- },
- TWD : {
- '20001': { cfid:20001, typename:'TWD', price:10, name:'1元档位'},
- '20002': { cfid:20002, typename:'TWD', price:20, name:'3元档位'},
- '20003': { cfid:20003, typename:'TWD', price:33, name:'6元档位'},
- '20004': { cfid:20004, typename:'TWD', price:45, name:'8元档位'},
- '20005': { cfid:20005, typename:'TWD', price:65, name:'12元档位'},
- '20006': { cfid:20006, typename:'TWD', price:100, name:'18元档位'},
- '20007': { cfid:20007, typename:'TWD', price:170, name:'30元档位'},
- '20008': { cfid:20008, typename:'TWD', price:330, name:'68元档位'},
- '20009': { cfid:20009, typename:'TWD', price:490, name:'98元档位'},
- '20010': { cfid:20010, typename:'TWD', price:640, name:'128元档位'},
- '20011': { cfid:20011, typename:'TWD', price:990, name:'198元档位'},
- '20012': { cfid:20012, typename:'TWD', price:1690, name:'328元档位'},
- '20013': { cfid:20013, typename:'TWD', price:2450, name:'488元档位'},
- '20014': { cfid:20014, typename:'TWD', price:3290, name:'648元档位'},
- },
- }
- // Android 产品包的配置数据
- var Android = {
- editor : template.std, // 测试渠道
- shengtiancny : template.CNY, // 圣天
- shengtianhkd : template.HKD, // 圣天
- shengtiantwd : template.TWD, // 圣天
- shengtianusd : template.USD, // 圣天
- }
- // iOS 产品包的配置数据
- var IOS = {
- yudha : template.yudha,
- yuda_abd : template.yuda_abd,
- yuda_abdof : template.yuda_abd,
- }
- //谷歌的验证密钥
- var GooglePlay_SIG = {
- // 'com.mgames.pixel.en' : {
- // sig : 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5XPAAyaVLvvp5tleB2lpDgsDBOOt3Jly/HycNJGGAZe/80niCLe1Tdu6OVzjHCjm4KDxQvcHGUxjbKZK53nsR+zLG1oahk+uBG99BBhnqm3QuYQYoBZs0zj56qqyCkz0r8Nj/TenwBLliYiA4i/z/LIPL+71Z7NBamxH1GqK1JL+E/gNdwI6r0lnEqFqfGqmB/hVP5jQa6ogxxY27f0lD7+p1QV7sDQfIzSGX+M49Notf10Ptesr0BNr6IkMFdQHZRPjdHJBmGAaBw4tAKk/HcyLH22NDexpSU2YOeyr4aMrQ89ydIHGO7KlgPel5Uag/h+ERHv12PrEE2pYrp0qCQIDAQAB',
- // },
- // 'com.jl3rd.zlwx.google' : { // yytx_dny
- // sig : 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApHXWDxtD66vELk6/Xdz0G4CiKKZLfjCauJ1wqDuAxbx2K1jX8YZ56XfyS594sGtBapVpmweLWT6/YrKXpoRv0OXUCL1TFdFaD0S7F6Fvocxcwjq6VHUxd3d7X9ye0yyURDNdqo2phGZbo2HnAF8kzA2ohSNer3ZTLUqqj53Tv0lUjIEWYo5eI/N/F24xRHy5q1JTm+cuRczuUqN5Gh+gt8qAPYPRNTHTNg4WRjGq097ONLnvjzisjubUQiDaYOj1wbPyHYPypAltX0PVt1JnTQ1H/JlFgOUAjATipm41r9CQ2tZVuB98xetVwYpQLK6tS3HztnDmbN0XbhEFEUL+KwIDAQAB'
- // },
- }
- // IOS 中是否是沙盒测试的istest=1沙盒测试 2:正式
- var IOS_ISTEST = {
- // zd_ios: {istest : 1,},
- }
- /*
- channel: 渠道名
- istest: google 使用 (IOS 使用 IOS_ISTEST)
- 通过包名,查找对于的渠道标识
- */
- var appid_channel = {
- // "com.jl3rd.zlwx.google":{channel:"yytx_dny",istest:1 }, // yytx_dny(公司发行东南亚) //1是测试2是正式
- }
- // 通过 cifd 反向查找配置
- exports.reverse = function(platform, channel, cfid) {
- platform = platform ? platform.toLowerCase() : 'null'
- channel = channel ? channel.toLowerCase() : "null"
- cfid = cfid ? cfid : 'null'
- var hash = null;
- if (platform == "ios") {
- hash = IOS;
- } else if (platform == 'android') {
- hash = Android;
- } else if (platform == 'zayaweb') {
- hash = Web;
- }
- if (hash) {
- var option = hash[channel]
- if (option) {
- for (var key in option) {
- var ret = option[key];
- if (ret.cfid == cfid) {
- return ret
- }
- }
- }
- }
- return { cfid:0, typename:'', price:0, diamond:0 }
- }
- // 解析(在google/ios设置的档位名称) xxx.xxx.1001 返回最后的数据
- exports.parse_end = function(key){
- var a = key.split('.');
- var len = a.length;
- if (len > 0) {
- key = parseInt(a[len-1]);
- if(!key){
- key = a[len-1];
- }
- }
- return key
- }
- exports.parse = function(platform,channel,key) {
- platform = platform ? platform.toLowerCase() : 'null'
- channel = channel ? channel.toLowerCase() : "null"
- console.log(channel)
- key = key ? key : 'null'
- var hash = null;
- if (platform == 'ios') {
- if (key) {
- var a = key.split('.');
- var len = a.length;
- if (len > 0) {
- key = parseInt(a[len-1]);
- if(!key){
- key = a[len-1];
- }
- hash = IOS;
- }
- }
- } else if (platform == 'android') {
- key = parseInt(key);
- hash = Android;
- } else if(platform == 'googleplay'){
- if (key) {
- var a = key.split('.');
- var len = a.length;
- if (len > 0) {
- key = parseInt(a[len-1]);
- if(!key){
- key = a[len-1];
- }
- hash = Android;
- if(hash.editor && hash.editor[key]){
- return hash.editor[key]
- }
- }
- }
- } else if(platform == "web"){
- key = parseInt(key);
- hash = Web;
- }
- if (hash) {
- var option = hash[channel];
- if (option && option[key]) {
- return option[key]
- }
- }
- return { cfid:0, typename:'', price:0, diamond:0 }
- }
- //@TODO: 是否存在该渠道
- exports.allowed_ios_channel = function(channel) {
- var option = IOS[channel];
- return option ? true : false
- }
- //@TODO: 充值模式获取
- exports.get_ios_istest = function(channel){
- var option = IOS_ISTEST[channel];
- console.log("option.istest:%s",option.istest)
- if (option && (option.istest || 0 == option.istest)){
- return option.istest
- }
- return 2
- }
- //@TODO: 是否是安卓的充值
- exports.allowed_android_channel = function(channel) {
- var option = Android[channel];
- return option ? true : false
- }
- //@TODO: google充值秘钥
- exports.get_googleplay_sig = function(channel){
- var option = GooglePlay_SIG[channel];
- if (option && option.sig){
- return option.sig
- }
- return 2
- }
- // 配置 TalkingData 的 AppID
- exports.getAppID = function(channel) {
- if (channel=="yudha"){
- return "0FE175A24C984525AD76DBE6A46031A0"; // 屠龙简体
- }
- else if(channel == 'yuda_abd'){
- return "91BF1908F5554C0E8DF31C2F9B180A3E"; // 屠龙港澳台
- }
- else if(channel == 'yuda_abdof'){
- return "0645B126AF3642A8AF8A510BF657BA64"; // 屠龙港澳台3测
- }
- else {
- return null;
- }
- }
- // google 通过包名获取渠道配置
- exports.get_channel = function(open_appid){
- if (appid_channel[open_appid]){
- return appid_channel[open_appid].channel;
- }
- }
- // 获取 是否测试标识
- exports.get_istest = function(open_appid) {
- // console.log("####get_istest %s", open_appid)
- if (appid_channel[open_appid]){
- return appid_channel[open_appid].istest;
- }
- return 3
- }
- // 卓动 是否验证 md5(小游戏使用)
- exports.get_verify = function(open_appid) {
- if (appid_channel[open_appid]){
- return appid_channel[open_appid].verify;
- }
- return false;
- }
- //@TODO: 将传入的 data数据, 拼接在一起
- exports.url_sort = function(data){
- var sort_data = Object.keys(data).sort();
- // 生成本地签名验证签名
- var strsign = data[sort_data[0]];
- for(var i=1;i<sort_data.length;i++){
- if(sort_data[i] != "sign"){
- strsign = strsign + '&'+ data[sort_data[i]]
- }
- }
- return strsign
- }
- exports.url_sort2 = function(data){
- var sort_data = Object.keys(data).sort();
- // 生成本地签名验证签名
- var strsign = sort_data[0]+'='+data[sort_data[0]];
- for(var i=1;i<sort_data.length;i++){
- if(sort_data[i] != "sign"){
- strsign = strsign + '&'+ sort_data[i] + '=' + data[sort_data[i]]
- }
- }
- return strsign
- }
|