@xyz-fe/log 3.8.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +137 -9
- package/dist/index.js +4 -2
- package/dist/index.min.js +4 -2
- package/dist/index.mjs +4 -2
- package/dist/mp.d.ts +82 -7
- package/dist/mp.js +2 -2
- package/dist/mp.min.js +2 -2
- package/dist/mp.mjs +2 -2
- package/dist/web-hw.d.ts +80 -6
- package/dist/web-hw.js +3 -3
- package/dist/web-hw.min.js +3 -3
- package/dist/web-hw.mjs +3 -3
- package/dist/web.d.ts +73 -6
- package/dist/web.js +2 -2
- package/dist/web.min.js +2 -2
- package/dist/web.mjs +2 -2
- package/package.json +8 -12
- package/dist/index.js.map +0 -1
- package/dist/index.min.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/mp.js.map +0 -1
- package/dist/mp.min.js.map +0 -1
- package/dist/mp.mjs.map +0 -1
- package/dist/web-hw.js.map +0 -1
- package/dist/web-hw.min.js.map +0 -1
- package/dist/web-hw.mjs.map +0 -1
- package/dist/web.js.map +0 -1
- package/dist/web.min.js.map +0 -1
- package/dist/web.mjs.map +0 -1
package/dist/mp.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface TCommonParams {
|
|
|
8
8
|
unionid?: string;
|
|
9
9
|
accid?: string;
|
|
10
10
|
apptypeid?: string;
|
|
11
|
+
appsubid?: string;
|
|
11
12
|
appcqid?: string;
|
|
12
13
|
srcqid?: string;
|
|
13
14
|
userinfo?: string;
|
|
@@ -31,6 +32,7 @@ interface IOpenLogParams {
|
|
|
31
32
|
xmlog: string;
|
|
32
33
|
isreturn?: 0 | 1 | 2 | 3;
|
|
33
34
|
querystring?: Record<string | number, any>;
|
|
35
|
+
manual?: boolean;
|
|
34
36
|
}
|
|
35
37
|
interface IActiveLogParams {
|
|
36
38
|
actentryid?: string;
|
|
@@ -66,15 +68,26 @@ interface IOnlineLogParams {
|
|
|
66
68
|
starttime: string;
|
|
67
69
|
}
|
|
68
70
|
declare type IOnlineLogParamsWithCommon = ICommonParams & IOnlineLogParams;
|
|
71
|
+
declare type IHwOnlineLogParamsWithCommon = IHwCommonParams & IOnlineLogParams;
|
|
69
72
|
interface IUserInfo {
|
|
70
73
|
[k: string | number]: any;
|
|
71
74
|
}
|
|
72
|
-
interface
|
|
73
|
-
language
|
|
75
|
+
interface ISystemInfo {
|
|
76
|
+
language?: string;
|
|
77
|
+
version: string;
|
|
78
|
+
SDKVersion?: string;
|
|
79
|
+
benchmarkLevel?: number;
|
|
80
|
+
theme?: string;
|
|
81
|
+
platform: string;
|
|
82
|
+
system: string;
|
|
83
|
+
model: string;
|
|
84
|
+
brand: string;
|
|
85
|
+
pixelRatio: number;
|
|
86
|
+
screenWidth: number;
|
|
87
|
+
screenHeight: number;
|
|
88
|
+
}
|
|
89
|
+
interface IExtraInfo extends Pick<ISystemInfo, 'language' | 'SDKVersion' | 'benchmarkLevel' | 'theme' | 'pixelRatio'> {
|
|
74
90
|
wxVersion: string;
|
|
75
|
-
SDKVersion: string;
|
|
76
|
-
benchmarkLevel: number;
|
|
77
|
-
theme: string;
|
|
78
91
|
}
|
|
79
92
|
interface IDomain {
|
|
80
93
|
open?: string;
|
|
@@ -135,6 +148,7 @@ interface IHwDomain {
|
|
|
135
148
|
open?: string;
|
|
136
149
|
act?: string;
|
|
137
150
|
ad?: string;
|
|
151
|
+
onlineUrl?: string;
|
|
138
152
|
}
|
|
139
153
|
interface HwInitParams {
|
|
140
154
|
isPro?: boolean;
|
|
@@ -169,6 +183,59 @@ interface IHwAdLogParams {
|
|
|
169
183
|
ecpm?: string;
|
|
170
184
|
adfrom?: string;
|
|
171
185
|
}
|
|
186
|
+
interface IRes<T = any> {
|
|
187
|
+
code: string;
|
|
188
|
+
msg: string;
|
|
189
|
+
data: T;
|
|
190
|
+
}
|
|
191
|
+
interface ICode2sessionParams {
|
|
192
|
+
apptypeid: string;
|
|
193
|
+
code: string;
|
|
194
|
+
testNet?: string | number;
|
|
195
|
+
}
|
|
196
|
+
interface ICode2sessionResponseData {
|
|
197
|
+
unionid?: string;
|
|
198
|
+
openid: string;
|
|
199
|
+
session_key: string;
|
|
200
|
+
}
|
|
201
|
+
interface IShareParams {
|
|
202
|
+
apptypeid: string;
|
|
203
|
+
openId: string;
|
|
204
|
+
}
|
|
205
|
+
interface ISubsidyParams extends IShareParams {
|
|
206
|
+
os: string;
|
|
207
|
+
}
|
|
208
|
+
interface ISubsidyResponseData {
|
|
209
|
+
hasSubsidy: boolean;
|
|
210
|
+
ksSubsidyLevelDetails: {
|
|
211
|
+
buyQuantity: string;
|
|
212
|
+
money: number;
|
|
213
|
+
subsidyMoney: number;
|
|
214
|
+
subsidyAfterMoney: number;
|
|
215
|
+
}[];
|
|
216
|
+
}
|
|
217
|
+
declare type IUserPropsParams = IShareParams;
|
|
218
|
+
interface IUserPropsResponseData {
|
|
219
|
+
[k: string]: string | number;
|
|
220
|
+
}
|
|
221
|
+
interface ICheckOrderParams extends IShareParams {
|
|
222
|
+
orderId: string;
|
|
223
|
+
}
|
|
224
|
+
interface ICheckOrderResponseData {
|
|
225
|
+
payResult: string | number;
|
|
226
|
+
}
|
|
227
|
+
interface ICreateOrderParams extends IShareParams {
|
|
228
|
+
productId?: string;
|
|
229
|
+
payPlatform?: string;
|
|
230
|
+
}
|
|
231
|
+
interface ICreateOrderResponseData {
|
|
232
|
+
payContent: any;
|
|
233
|
+
amount: string;
|
|
234
|
+
amountCents: string;
|
|
235
|
+
orderId: string;
|
|
236
|
+
productId: string;
|
|
237
|
+
productName: string;
|
|
238
|
+
}
|
|
172
239
|
|
|
173
240
|
declare class XLog {
|
|
174
241
|
version: string;
|
|
@@ -178,6 +245,7 @@ declare class XLog {
|
|
|
178
245
|
private _actUrl;
|
|
179
246
|
private _adUrl;
|
|
180
247
|
private _onlineUrl;
|
|
248
|
+
private _businessDomain;
|
|
181
249
|
private _startTime;
|
|
182
250
|
private _extraInfo?;
|
|
183
251
|
private _commonParams;
|
|
@@ -190,6 +258,8 @@ declare class XLog {
|
|
|
190
258
|
private _platform;
|
|
191
259
|
private _consoleLog;
|
|
192
260
|
constructor({ domain, commonParams, isPro, sendOpenLog, consoleLog, }: InitParams);
|
|
261
|
+
private _getLaunchOptions;
|
|
262
|
+
private _updateQuerystring;
|
|
193
263
|
/** 启动 */
|
|
194
264
|
private _init;
|
|
195
265
|
private _getMp;
|
|
@@ -208,7 +278,7 @@ declare class XLog {
|
|
|
208
278
|
private _initCommonParams;
|
|
209
279
|
private _getNetworkType;
|
|
210
280
|
/**
|
|
211
|
-
*
|
|
281
|
+
* 合并用户信息
|
|
212
282
|
* @param {IUserInfo} userInfo 用户信息
|
|
213
283
|
* @returns {string} JSON.stringify序列化字符串
|
|
214
284
|
*/
|
|
@@ -229,6 +299,11 @@ declare class XLog {
|
|
|
229
299
|
act(params: IActiveLogParams): void;
|
|
230
300
|
/** 上报广告日志 */
|
|
231
301
|
ad(params: IAdLogParams): void;
|
|
302
|
+
code2session(params: ICode2sessionParams): Promise<IRes<ICode2sessionResponseData>>;
|
|
303
|
+
getSubsidy(params: ISubsidyParams): Promise<IRes<ISubsidyResponseData>>;
|
|
304
|
+
getUserProps(params: IUserPropsParams): Promise<IRes<IUserPropsResponseData>>;
|
|
305
|
+
checkOrder(params: ICheckOrderParams): Promise<IRes<ICheckOrderResponseData>>;
|
|
306
|
+
createOrder(params: ICreateOrderParams): Promise<IRes<ICreateOrderResponseData>>;
|
|
232
307
|
private _sendOnline;
|
|
233
308
|
private _setOnlineBatchData;
|
|
234
309
|
private _getOnlineBatchData;
|
|
@@ -236,4 +311,4 @@ declare class XLog {
|
|
|
236
311
|
private _online;
|
|
237
312
|
}
|
|
238
313
|
|
|
239
|
-
export { EGender, HwInitParams, IActiveLogParams, IAdLogParams, ICommonParams, IDomain, IDomainWithEnv, IEventLogParams, IExtraInfo, IHwActiveLogParams, IHwAdLogParams, IHwCommonParams, IHwDomain, IHwOpenLogParams, IOnlineLogParams, IOnlineLogParamsWithCommon, IOpenLogParams, IUserInfo, InitParams, MiniprogramShowOptions, TCommonParams, THwCommonParams, TPlatform, XLog };
|
|
314
|
+
export { EGender, HwInitParams, IActiveLogParams, IAdLogParams, ICheckOrderParams, ICheckOrderResponseData, ICode2sessionParams, ICode2sessionResponseData, ICommonParams, ICreateOrderParams, ICreateOrderResponseData, IDomain, IDomainWithEnv, IEventLogParams, IExtraInfo, IHwActiveLogParams, IHwAdLogParams, IHwCommonParams, IHwDomain, IHwOnlineLogParamsWithCommon, IHwOpenLogParams, IOnlineLogParams, IOnlineLogParamsWithCommon, IOpenLogParams, IRes, IShareParams, ISubsidyParams, ISubsidyResponseData, ISystemInfo, IUserInfo, IUserPropsParams, IUserPropsResponseData, InitParams, MiniprogramShowOptions, TCommonParams, THwCommonParams, TPlatform, XLog };
|
package/dist/mp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @xyz-fe/log
|
|
2
|
+
* @xyz-fe/log v4.0.0
|
|
3
3
|
* (c) lizhigao <lizhigao@021.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){return t=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(){var t=new Date,e=t.getFullYear().toString(),o=(t.getMonth()+1).toString(),n=t.getDate().toString();return(e=e.toString().substr(-2))+(o=Number(o)<10?"0"+o:o)+(n=Number(n)<10?"0"+n:n)}function o(e,o){var n=t({},e),i=t({},o);return Object.keys(n).forEach((function(t){i[t]||delete i[t]})),t(t({},n),i)}var n;exports.EGender=void 0,(n=exports.EGender||(exports.EGender={}))[n.Unknown=0]="Unknown",n[n.Male=1]="Male",n[n.Female=2]="Female";var i=function(){function n(t){var e,o=t.domain,n=t.commonParams,i=t.isPro,r=void 0===i||i,s=t.sendOpenLog,a=void 0===s||s,p=t.consoleLog,c=void 0===p||p;this.version="3.8.1",this.buildDate="2/20/2025, 10:28:18 AM",this._openUrl="",this._eventUrl="",this._actUrl="",this._adUrl="",this._onlineUrl="",this._startTime=Date.now(),this._commonParams={},this._isPro=!0,this._sendOpenLog=!0,this._isColdStartUp=!0,this._systemInfo={},this._mp={},this._consoleLog=!0,this._isPro=r,this._sendOpenLog=a,this._consoleLog=c;var l=this._getApis(o),h=l.openUrl,m=l.eventUrl,u=l.actUrl,_=l.adUrl,d=l.onlineUrl;this._openUrl=h,this._eventUrl=m,this._actUrl=u,this._adUrl=_,this._onlineUrl=d;var f,g=this._getMp(),y=g.mp,v=g.platform;this._mp=y,this._platform=v,!y||(f=y)&&0===Object.keys(f).length&&f.constructor===Object?console.error("[XLOG] 日志SDK初始化失败,当前环境为非小程序环境!"):this._consoleLog&&console.log("[XLOG] 小程序对象:",y);try{this._systemInfo=(null===(e=this._mp)||void 0===e?void 0:e.getSystemInfoSync())||{}}catch(t){console.error("[XLOG] getSystemInfoSync error",t)}this._extraInfo={language:this._systemInfo.language,wxVersion:this._systemInfo.version,SDKVersion:this._systemInfo.SDKVersion,benchmarkLevel:this._systemInfo.benchmarkLevel||-1,theme:this._systemInfo.theme},this._init(n)}return Object.defineProperty(n.prototype,"commonParams",{get:function(){return this._commonParams},enumerable:!1,configurable:!0}),n.prototype._init=function(t){var e=this;this._initCommonParams(this._filterParams(t)),this._coldStartUp(),this._visibilityChange((function(){e._isColdStartUp||e._getNetworkType().then((function(t){e._updateCommonParams({network:t}),e._open({openway:1})})),e._startTime=Date.now();var t=e._getOnlineBatchData();t&&e._online(t)}),(function(){e._isColdStartUp=!1,e._open({openway:5}),e._sendOnline()}))},n.prototype._getMp=function(){var t={mp:null,platform:7};return"undefined"!=typeof tt?(t.mp=tt,t.platform=2):"undefined"!=typeof ks?(t.mp=ks,t.platform=3):"undefined"!=typeof swan?(t.mp=swan,t.platform=4):"undefined"!=typeof qq?(t.mp=qq,t.platform=5):"undefined"!=typeof wx?(t.mp=wx,t.platform=1):"undefined"!=typeof my?t.mp=my:"undefined"!=typeof jd&&(t.mp=jd),t},n.prototype._visibilityChange=function(t,e){var o,n,i,r,s=this;void 0===t&&(t=function(){}),void 0===e&&(e=function(){});try{var a=(null===(o=this._mp)||void 0===o?void 0:o.onAppShow)||(null===(n=this._mp)||void 0===n?void 0:n.onShow)||function(){},p=(null===(i=this._mp)||void 0===i?void 0:i.onAppHide)||(null===(r=this._mp)||void 0===r?void 0:r.onHide)||function(){};a((function(){s._consoleLog&&console.log("[XLOG] onAppShow"),t()})),p((function(){s._consoleLog&&console.log("[XLOG] onAppHide"),e()}))}catch(t){console.error("[XLOG] onAppShow or onAppHide error",t)}},n.prototype._getStorage=function(t){var e;try{return null===(e=this._mp)||void 0===e?void 0:e.getStorageSync("XYZ_LOG_".concat(t))}catch(t){console.error("[XLOG] getStorageSync error",t)}},n.prototype._setStorage=function(t,e){var o;try{null===(o=this._mp)||void 0===o||o.setStorageSync("XYZ_LOG_".concat(t),e)}catch(t){console.error("[XLOG] setStorageSync error",t)}},n.prototype._getBatchId=function(){var t=this._getStorage("BATCH_ID");return t&&!this._isColdStartUp||(t=function(t,e){void 0===t&&(t=18),void 0===e&&(e=0);for(var o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=[],i=Math.random,r=t,s=e||o.length,a=0;a<r;a++)n[a]=o[0|i()*s];return n.join("")}(),this._setStorage("BATCH_ID",t)),t},n.prototype._coldStartUp=function(){var t=this;this._getNetworkType().then((function(e){t._updateCommonParams({network:e}),t._open({openway:0})}))},n.prototype._getApis=function(e){var o=this._isPro?{open:"webopen-inside.tt.cn",event:"webevent-inside.tt.cn",act:"webact-inside.tt.cn",ad:"webadv-inside.tt.cn",online:"webact-inside.tt.cn"}:{open:"test-webopen-inside.tt.cn",event:"test-webevent-inside.tt.cn",act:"test-webact-inside.tt.cn",ad:"test-webadv-inside.tt.cn",online:"test-webact-inside.tt.cn"},n=t(t({},o),e);return{openUrl:"https://".concat(n.open,"/gamefunction_logs/applet/open"),eventUrl:"https://".concat(n.event,"/gamefunction_logs/applet/event"),actUrl:"https://".concat(n.act,"/gamefunction_logs/applet/activity"),adUrl:"https://".concat(n.ad,"/gamefunction_logs/applet/adv"),onlineUrl:"https://".concat(n.online,"/gamefunction_logs/applet/onlineTime")}},n.prototype._cacheCommonParams=function(t){this._setStorage("COMMON_PARAMS",JSON.stringify(t))},n.prototype._getInitParams=function(){return{platform:this._platform,appcqid:"organic",appqid:"organic"+e(),os:this._systemInfo.platform,osversion:this._systemInfo.system&&this._systemInfo.system.split(" ")[1],device:this._systemInfo.model,devicebrand:this._systemInfo.brand,pixel:this._systemInfo.screenWidth+"*"+this._systemInfo.screenHeight,userinfo:this._getUserInfo()}},n.prototype._initCommonParams=function(e){var n=this._getInitParams(),i=this._getStorage("COMMON_PARAMS");i&&(n=t(t({},n),JSON.parse(i))),n=e?o(n,e):n,this._updateCommonParams(t(t({},n),{obatchid:this._getBatchId()}))},n.prototype._getNetworkType=function(){var t=this;return new Promise((function(e){var o;try{null===(o=t._mp)||void 0===o||o.getNetworkType({success:function(t){e(t.networkType)},fail:function(){e("none")}})}catch(t){e("none"),console.error("[XLOG] getNetworkType error",t)}}))},n.prototype._getUserInfo=function(e){var o={};if(e)try{o=JSON.parse(e)}catch(t){console.error('[XLOG] The parameter "userinfo" is not in JSON string format!')}var n={};if(this.commonParams.userinfo)try{n=JSON.parse(this.commonParams.userinfo)}catch(t){console.error("[XLOG] parse error",t)}return JSON.stringify(t(t(t({},this._extraInfo),n),o))},n.prototype._filterParams=function(t){var e={};if(t){var o=["openid","unionid","accid","apptypeid","appcqid","srcqid","appver","userinfo"];for(var n in t){var i=t[n];o.includes(n)&&i&&(e[n]=i)}}return e},n.prototype.setParams=function(t){if(t){this._consoleLog&&console.log("[XLOG] setParams",t);var e=this._commonParams.openid,o=this._commonParams.unionid;t=this._filterParams(t),this._updateCommonParams(t),(t.openid&&t.openid!==e||t.unionid&&t.unionid!==o)&&this._open({isreturn:t.openid?1:2,openway:0})}},n.prototype._updateCommonParams=function(t){this._consoleLog&&console.log("[XLOG] _updateCommonParams",t),t.userinfo&&(t.userinfo=this._getUserInfo(t.userinfo)),t.appcqid&&(t.appqid=t.appcqid+e()),t.appver&&(t.appverint=function(t){try{return t&&"string"==typeof t?t.split(".").map((function(t){return 1===t.length?"0"+t:t})).join(""):""}catch(e){return console.error('[transferVersion] ver("'.concat(t,'")格式异常:'),e),""}}(t.appver)),this._commonParams=o(this._commonParams,t),this._cacheCommonParams(this._commonParams)},n.prototype._getAppqid=function(){return this._commonParams.appcqid+e()},n.prototype._request=function(t,e,o){var n=this;return void 0===o&&(o="application/x-www-form-urlencoded"),new Promise((function(i,r){var s;try{null===(s=n._mp)||void 0===s||s.request({url:t,data:e,method:"POST",header:{"content-type":o},success:function(o){n._consoleLog&&console.log("[XLOG] SUCCESS: ".concat(t),e,o),i(o)},fail:function(o){n._consoleLog&&console.log("[XLOG] FAIL: ".concat(t),e,o),r(o)}})}catch(t){console.error("[XLOG] request error",t)}}))},n.prototype.open=function(t){this._open({querystring:t.querystring,isreturn:3,openway:0})},n.prototype._open=function(e){var o,n,i=null;try{i=((null===(o=this._mp)||void 0===o?void 0:o.getEnterOptionsSync)||(null===(n=this._mp)||void 0===n?void 0:n.getLaunchOptionsSync)||function(){})()}catch(t){console.error("[XLOG] getEnterOptionsSync error",t)}if((null==i?void 0:i.query)?this._updateCommonParams({userinfo:JSON.stringify({querystring:t(t({},i.query),e.querystring)})}):this._updateCommonParams({userinfo:JSON.stringify({querystring:e.querystring})}),this._sendOpenLog){var r=t(t({},this._commonParams),{appqid:this._getAppqid(),wakeway:e.wakeway||(null==i?void 0:i.scene)||"",openway:e.openway,isreturn:e.isreturn||0,xmlog:"3.8.1"});this._consoleLog&&console.log("[XLOG] PARAMS(OPEN)",r),this._request(this._openUrl,r)}},n.prototype.event=function(e){var o=t(t({},this._commonParams),{appqid:this._getAppqid(),event1:e.event1||"",event2:e.event2||"",event3:e.event3||"",event4:e.event4||"",value1:e.value1||"",value2:e.value2||"",value3:e.value3||"",value4:e.value4||""});this._consoleLog&&console.log("[XLOG] PARAMS(EVENT)",o),this._request(this._eventUrl,o)},n.prototype.act=function(e){var o=t(t({},this._commonParams),{appqid:this._getAppqid(),actentryid:e.actentryid||"",subactid:e.subactid||"",type:e.type||"",custom:e.custom||"",batchid:e.batchid||""});this._consoleLog&&console.log("[XLOG] PARAMS(ACT)",o),this._request(this._actUrl,o)},n.prototype.ad=function(e){var o=t(t({},this._commonParams),{appqid:this._getAppqid(),type:e.type||"",code:e.code||"",codeinfo:e.codeinfo||"",pagetype:e.pagetype||"",gametype:e.gametype||"",adslot:e.adslot||"",adunitid:e.adunitid||"",adbatchid:e.adbatchid||"",ecpm:e.ecpm||""});this._consoleLog&&console.log("[XLOG] PARAMS(AD)",o),this._request(this._adUrl,o,"application/json")},n.prototype._sendOnline=function(){var e=Date.now(),o=t(t({},this._commonParams),{appqid:this._getAppqid(),onlinetime:"".concat(e-this._startTime),endtime:e.toString(),starttime:this._startTime.toString()});this._online([o])},n.prototype._setOnlineBatchData=function(t){this._setStorage("ONLINE_BACH_DATA",t)},n.prototype._getOnlineBatchData=function(){return this._getStorage("ONLINE_BACH_DATA")},n.prototype._clearOnlineBatchData=function(){this._setStorage("ONLINE_BACH_DATA","")},n.prototype._online=function(t){var e=this;this._consoleLog&&console.log("[XLOG] PARAMS(ONLINE)",t),this._clearOnlineBatchData(),this._request(this._onlineUrl,{batch:JSON.stringify(t)}).catch((function(o){e._setOnlineBatchData(t)}))},n}();exports.XLog=i;
|
|
6
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{p(o.next(t))}catch(t){r(t)}}function a(t){try{p(o.throw(t))}catch(t){r(t)}}function p(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}p((o=o.apply(t,e||[])).next())}))}function n(t,e){var n,o,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,o=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],o=0}finally{n=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}function o(){var t=new Date,e=t.getFullYear().toString(),n=(t.getMonth()+1).toString(),o=t.getDate().toString();return(e=e.toString().substr(-2))+(n=Number(n)<10?"0"+n:n)+(o=Number(o)<10?"0"+o:o)}function i(e,n){var o=t({},e),i=t({},n);return Object.keys(o).forEach((function(t){i[t]||delete i[t]})),t(t({},o),i)}var r;exports.EGender=void 0,(r=exports.EGender||(exports.EGender={}))[r.Unknown=0]="Unknown",r[r.Male=1]="Male",r[r.Female=2]="Female";var s=function(){function r(t){var e,n=t.domain,o=t.commonParams,i=t.isPro,r=void 0===i||i,s=t.sendOpenLog,a=void 0===s||s,p=t.consoleLog,c=void 0===p||p;this.version="4.0.0",this.buildDate="3/7/2025, 6:00:43 PM",this._openUrl="",this._eventUrl="",this._actUrl="",this._adUrl="",this._onlineUrl="",this._businessDomain="",this._startTime=Date.now(),this._commonParams={},this._isPro=!0,this._sendOpenLog=!0,this._isColdStartUp=!0,this._systemInfo={},this._mp={},this._consoleLog=!0,this._isPro=r,this._sendOpenLog=a,this._consoleLog=c;var u=this._getApis(n),l=u.openUrl,h=u.eventUrl,d=u.actUrl,m=u.adUrl,_=u.onlineUrl;this._openUrl=l,this._eventUrl=h,this._actUrl=d,this._adUrl=m,this._onlineUrl=_,this._businessDomain=this._isPro?"https://applet-xx.mop.com":"https://test-applet-xx.mop.com";var f,y=this._getMp(),g=y.mp,v=y.platform;this._mp=g,this._platform=v,!g||(f=g)&&0===Object.keys(f).length&&f.constructor===Object?console.error("[XLOG] 日志SDK初始化失败,当前环境为非小程序环境!"):this._consoleLog&&console.log("[XLOG] 小程序对象:",g);try{this._systemInfo=(null===(e=this._mp)||void 0===e?void 0:e.getSystemInfoSync())||{}}catch(t){console.error("[XLOG] getSystemInfoSync error",t)}this._extraInfo={language:this._systemInfo.language,wxVersion:this._systemInfo.version,SDKVersion:this._systemInfo.SDKVersion,benchmarkLevel:this._systemInfo.benchmarkLevel||-1,theme:this._systemInfo.theme,pixelRatio:this._systemInfo.pixelRatio},this._init(o)}return Object.defineProperty(r.prototype,"commonParams",{get:function(){return this._commonParams},enumerable:!1,configurable:!0}),r.prototype._getLaunchOptions=function(){var t,e,n=null;try{n=((null===(t=this._mp)||void 0===t?void 0:t.getEnterOptionsSync)||(null===(e=this._mp)||void 0===e?void 0:e.getLaunchOptionsSync)||function(){})()}catch(t){console.error("[XLOG] getEnterOptionsSync or getLaunchOptionsSync error",t)}return n},r.prototype._updateQuerystring=function(e,n){void 0===e&&(e=null),void 0===n&&(n={}),(null==e?void 0:e.query)?this._updateCommonParams({srcqid:e.query.channel||"",userinfo:JSON.stringify({querystring:t(t({},e.query),n)})}):this._updateCommonParams({userinfo:JSON.stringify({querystring:n})})},r.prototype._init=function(t){var e=this;this._initCommonParams(this._filterParams(t));var n=this._getLaunchOptions();this._updateQuerystring(n),this._coldStartUp(),this._visibilityChange((function(){e._isColdStartUp||e._getNetworkType().then((function(t){e._updateCommonParams({network:t}),e._open({openway:1})})),e._startTime=Date.now();var t=e._getOnlineBatchData();t&&e._online(t)}),(function(){e._isColdStartUp=!1,e._open({openway:5}),e._sendOnline()}))},r.prototype._getMp=function(){var t={mp:null,platform:7};return"undefined"!=typeof tt?(t.mp=tt,t.platform=2):"undefined"!=typeof ks?(t.mp=ks,t.platform=3):"undefined"!=typeof swan?(t.mp=swan,t.platform=4):"undefined"!=typeof qq?(t.mp=qq,t.platform=5):"undefined"!=typeof wx?(t.mp=wx,t.platform=1):"undefined"!=typeof my?t.mp=my:"undefined"!=typeof jd&&(t.mp=jd),t},r.prototype._visibilityChange=function(t,e){var n,o,i,r,s=this;void 0===t&&(t=function(){}),void 0===e&&(e=function(){});try{var a=(null===(n=this._mp)||void 0===n?void 0:n.onAppShow)||(null===(o=this._mp)||void 0===o?void 0:o.onShow)||function(){},p=(null===(i=this._mp)||void 0===i?void 0:i.onAppHide)||(null===(r=this._mp)||void 0===r?void 0:r.onHide)||function(){};a((function(){s._consoleLog&&console.log("[XLOG] onAppShow"),t()})),p((function(){s._consoleLog&&console.log("[XLOG] onAppHide"),e()}))}catch(t){console.error("[XLOG] onAppShow or onAppHide error",t)}},r.prototype._getStorage=function(t){var e;try{return null===(e=this._mp)||void 0===e?void 0:e.getStorageSync("XYZ_LOG_".concat(t))}catch(t){console.error("[XLOG] getStorageSync error",t)}},r.prototype._setStorage=function(t,e){var n;try{null===(n=this._mp)||void 0===n||n.setStorageSync("XYZ_LOG_".concat(t),e)}catch(t){console.error("[XLOG] setStorageSync error",t)}},r.prototype._getBatchId=function(){var t=this._getStorage("BATCH_ID");return t&&!this._isColdStartUp||(t=function(t,e){void 0===t&&(t=18),void 0===e&&(e=0);for(var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),o=[],i=Math.random,r=t,s=e||n.length,a=0;a<r;a++)o[a]=n[0|i()*s];return o.join("")}(),this._setStorage("BATCH_ID",t)),t},r.prototype._coldStartUp=function(){var t=this;this._getNetworkType().then((function(e){t._updateCommonParams({network:e}),t._open({openway:0})}))},r.prototype._getApis=function(e){var n=this._isPro?{open:"webopen-inside.tt.cn",event:"webevent-inside.tt.cn",act:"webact-inside.tt.cn",ad:"webadv-inside.tt.cn",online:"webact-inside.tt.cn"}:{open:"test-webopen-inside.tt.cn",event:"test-webevent-inside.tt.cn",act:"test-webact-inside.tt.cn",ad:"test-webadv-inside.tt.cn",online:"test-webact-inside.tt.cn"},o=t(t({},n),e);return{openUrl:"https://".concat(o.open,"/gamefunction_logs/applet/open"),eventUrl:"https://".concat(o.event,"/gamefunction_logs/applet/event"),actUrl:"https://".concat(o.act,"/gamefunction_logs/applet/activity"),adUrl:"https://".concat(o.ad,"/gamefunction_logs/applet/adv"),onlineUrl:"https://".concat(o.online,"/gamefunction_logs/applet/onlineTime")}},r.prototype._cacheCommonParams=function(t){this._setStorage("COMMON_PARAMS",JSON.stringify(t))},r.prototype._getInitParams=function(){var t,e=(null===(t=this._systemInfo.system)||void 0===t?void 0:t.includes(" "))?this._systemInfo.system.split(" ")[1]:this._systemInfo.system;return{platform:this._platform,appcqid:"organic",appqid:"organic"+o(),os:this._systemInfo.platform,osversion:e,device:this._systemInfo.model,devicebrand:this._systemInfo.brand,pixel:this._systemInfo.screenWidth+"*"+this._systemInfo.screenHeight,userinfo:this._getUserInfo()}},r.prototype._initCommonParams=function(e){var n=this._getInitParams(),o=this._getStorage("COMMON_PARAMS");o&&(n=t(t({},n),JSON.parse(o))),n=e?i(n,e):n,this._updateCommonParams(t(t({},n),{obatchid:this._getBatchId()}))},r.prototype._getNetworkType=function(){var t=this;return new Promise((function(e){var n;try{null===(n=t._mp)||void 0===n||n.getNetworkType({success:function(t){e(t.networkType)},fail:function(){e("none")}})}catch(t){e("none"),console.error("[XLOG] getNetworkType error",t)}}))},r.prototype._getUserInfo=function(e){var n={};if(e)try{n=JSON.parse(e)}catch(t){console.error('[XLOG] The parameter "userinfo" is not in JSON string format: ',e)}var o={};if(this.commonParams.userinfo)try{o=JSON.parse(this.commonParams.userinfo)}catch(t){console.error("[XLOG] parse error",t)}return JSON.stringify(t(t(t({},this._extraInfo),o),n))},r.prototype._filterParams=function(t){var e={};if(t){var n=["openid","unionid","accid","apptypeid","appsubid","appcqid","srcqid","appver","userinfo"];for(var o in t){var i=t[o];n.includes(o)&&i&&(e[o]=i)}}return e},r.prototype.setParams=function(t){if(t){this._consoleLog&&console.log("[XLOG] setParams",t);var e=this._commonParams.openid,n=this._commonParams.unionid;t=this._filterParams(t),this._updateCommonParams(t),(t.openid&&t.openid!==e||t.unionid&&t.unionid!==n)&&this._open({isreturn:t.openid?1:2,openway:0})}},r.prototype._updateCommonParams=function(e){this._consoleLog&&console.log("[XLOG] _updateCommonParams",e),e.userinfo&&(e.appsubid&&(e.userinfo=JSON.stringify(t(t({},JSON.parse(e.userinfo)),{appsubid:e.appsubid}))),e.userinfo=this._getUserInfo(e.userinfo)),e.appcqid&&(e.appqid=e.appcqid+o()),e.appver&&(e.appverint=function(t){try{return t&&"string"==typeof t?t.split(".").map((function(t){return 1===t.length?"0"+t:t})).join(""):""}catch(e){return console.error('[transferVersion] ver("'.concat(t,'")格式异常:'),e),""}}(e.appver)),this._commonParams=i(this._commonParams,e),this._cacheCommonParams(this._commonParams)},r.prototype._getAppqid=function(){return this._commonParams.appcqid+o()},r.prototype._request=function(t,e,n){var o=this;return void 0===n&&(n="application/x-www-form-urlencoded"),new Promise((function(i,r){var s;try{null===(s=o._mp)||void 0===s||s.request({url:t,data:e,method:"POST",header:{"content-type":n},success:function(n){o._consoleLog&&console.log("[XLOG] SUCCESS: ".concat(t),e,n),i(n)},fail:function(n){o._consoleLog&&console.log("[XLOG] FAIL: ".concat(t),e,n),r(n)}})}catch(t){console.error("[XLOG] request error",t),r(t)}}))},r.prototype.open=function(t){this._open({querystring:t.querystring,isreturn:3,openway:0,manual:!0})},r.prototype._open=function(e){if(this._sendOpenLog||e.manual){var n=this._getLaunchOptions();this._updateQuerystring(n,e.querystring);var o=t(t({},this._commonParams),{appqid:this._getAppqid(),wakeway:e.wakeway||(null==n?void 0:n.scene)||"",openway:e.openway,isreturn:e.isreturn||0,xmlog:"4.0.0"});this._consoleLog&&console.log("[XLOG] PARAMS(OPEN)",o),this._request(this._openUrl,o)}},r.prototype.event=function(e){var n=t(t({},this._commonParams),{appqid:this._getAppqid(),event1:e.event1||"",event2:e.event2||"",event3:e.event3||"",event4:e.event4||"",value1:e.value1||"",value2:e.value2||"",value3:e.value3||"",value4:e.value4||""});this._consoleLog&&console.log("[XLOG] PARAMS(EVENT)",n),this._request(this._eventUrl,n)},r.prototype.act=function(e){var n=t(t({},this._commonParams),{appqid:this._getAppqid(),actentryid:e.actentryid||"",subactid:e.subactid||"",type:e.type||"",custom:e.custom||"",batchid:e.batchid||""});this._consoleLog&&console.log("[XLOG] PARAMS(ACT)",n),this._request(this._actUrl,n)},r.prototype.ad=function(e){var n=t(t({},this._commonParams),{appqid:this._getAppqid(),type:e.type||"",code:e.code||"",codeinfo:e.codeinfo||"",pagetype:e.pagetype||"",gametype:e.gametype||"",adslot:e.adslot||"",adunitid:e.adunitid||"",adbatchid:e.adbatchid||"",ecpm:e.ecpm||""});this._consoleLog&&console.log("[XLOG] PARAMS(AD)",n),this._request(this._adUrl,n,"application/json")},r.prototype.code2session=function(t){return e(this,void 0,void 0,(function(){var e,o;return n(this,(function(n){switch(n.label){case 0:return e="",1===this._platform?e="wx/":3===this._platform&&(e="ks/"),o="".concat(this._businessDomain,"/AppletUtils/").concat(e,"code2session"),[4,this._request(o,{appTypeId:t.apptypeid,code:t.code,testNet:t.testNet},"application/json")];case 1:return[2,n.sent().data]}}))}))},r.prototype.getSubsidy=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/subsidy"),{apptypeid:t.apptypeid,os:this._systemInfo.platform,openId:t.openId},"application/json")];case 1:return[2,e.sent().data]}}))}))},r.prototype.getUserProps=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/userProps"),{appTypeId:t.apptypeid,openId:t.openId},"application/json")];case 1:return[2,e.sent().data]}}))}))},r.prototype.checkOrder=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/chkOrder"),{appTypeId:t.apptypeid,os:this._systemInfo.platform,openId:t.openId,orderId:t.orderId},"application/json")];case 1:return[2,e.sent().data]}}))}))},r.prototype.createOrder=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/crtOrder"),{appTypeId:t.apptypeid,os:this._systemInfo.platform,openId:t.openId,productId:t.productId,payPlatform:t.payPlatform},"application/json")];case 1:return[2,e.sent().data]}}))}))},r.prototype._sendOnline=function(){var e=Date.now(),n=t(t({},this._commonParams),{appqid:this._getAppqid(),onlinetime:"".concat(e-this._startTime),endtime:e.toString(),starttime:this._startTime.toString()});this._online([n])},r.prototype._setOnlineBatchData=function(t){this._setStorage("ONLINE_BACH_DATA",t)},r.prototype._getOnlineBatchData=function(){return this._getStorage("ONLINE_BACH_DATA")},r.prototype._clearOnlineBatchData=function(){this._setStorage("ONLINE_BACH_DATA","")},r.prototype._online=function(t){var e=this;this._consoleLog&&console.log("[XLOG] PARAMS(ONLINE)",t),this._clearOnlineBatchData(),this._request(this._onlineUrl,{batch:JSON.stringify(t)}).catch((function(n){e._setOnlineBatchData(t)}))},r}();exports.XLog=s;
|
|
7
7
|
//# sourceMappingURL=mp.js.map
|
package/dist/mp.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @xyz-fe/log
|
|
2
|
+
* @xyz-fe/log v4.0.0
|
|
3
3
|
* (c) lizhigao <lizhigao@021.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mp={})}(this,(function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function o(){var t=new Date,e=t.getFullYear().toString(),o=(t.getMonth()+1).toString(),n=t.getDate().toString();return(e=e.toString().substr(-2))+(o=Number(o)<10?"0"+o:o)+(n=Number(n)<10?"0"+n:n)}function n(t,o){var n=e({},t),i=e({},o);return Object.keys(n).forEach((function(t){i[t]||delete i[t]})),e(e({},n),i)}var i,r="3.8.1",s="organic";t.EGender=void 0,(i=t.EGender||(t.EGender={}))[i.Unknown=0]="Unknown",i[i.Male=1]="Male",i[i.Female=2]="Female";var a=function(){function t(t){var e,o=t.domain,n=t.commonParams,i=t.isPro,s=void 0===i||i,a=t.sendOpenLog,p=void 0===a||a,c=t.consoleLog,l=void 0===c||c;this.version=r,this.buildDate="2/20/2025, 10:28:18 AM",this._openUrl="",this._eventUrl="",this._actUrl="",this._adUrl="",this._onlineUrl="",this._startTime=Date.now(),this._commonParams={},this._isPro=!0,this._sendOpenLog=!0,this._isColdStartUp=!0,this._systemInfo={},this._mp={},this._consoleLog=!0,this._isPro=s,this._sendOpenLog=p,this._consoleLog=l;var h=this._getApis(o),m=h.openUrl,u=h.eventUrl,_=h.actUrl,d=h.adUrl,f=h.onlineUrl;this._openUrl=m,this._eventUrl=u,this._actUrl=_,this._adUrl=d,this._onlineUrl=f;var g,y=this._getMp(),v=y.mp,O=y.platform;this._mp=v,this._platform=O,!v||(g=v)&&0===Object.keys(g).length&&g.constructor===Object?console.error("[XLOG] 日志SDK初始化失败,当前环境为非小程序环境!"):this._consoleLog&&console.log("[XLOG] 小程序对象:",v);try{this._systemInfo=(null===(e=this._mp)||void 0===e?void 0:e.getSystemInfoSync())||{}}catch(t){console.error("[XLOG] getSystemInfoSync error",t)}this._extraInfo={language:this._systemInfo.language,wxVersion:this._systemInfo.version,SDKVersion:this._systemInfo.SDKVersion,benchmarkLevel:this._systemInfo.benchmarkLevel||-1,theme:this._systemInfo.theme},this._init(n)}return Object.defineProperty(t.prototype,"commonParams",{get:function(){return this._commonParams},enumerable:!1,configurable:!0}),t.prototype._init=function(t){var e=this;this._initCommonParams(this._filterParams(t)),this._coldStartUp(),this._visibilityChange((function(){e._isColdStartUp||e._getNetworkType().then((function(t){e._updateCommonParams({network:t}),e._open({openway:1})})),e._startTime=Date.now();var t=e._getOnlineBatchData();t&&e._online(t)}),(function(){e._isColdStartUp=!1,e._open({openway:5}),e._sendOnline()}))},t.prototype._getMp=function(){var t={mp:null,platform:7};return"undefined"!=typeof tt?(t.mp=tt,t.platform=2):"undefined"!=typeof ks?(t.mp=ks,t.platform=3):"undefined"!=typeof swan?(t.mp=swan,t.platform=4):"undefined"!=typeof qq?(t.mp=qq,t.platform=5):"undefined"!=typeof wx?(t.mp=wx,t.platform=1):"undefined"!=typeof my?t.mp=my:"undefined"!=typeof jd&&(t.mp=jd),t},t.prototype._visibilityChange=function(t,e){var o,n,i,r,s=this;void 0===t&&(t=function(){}),void 0===e&&(e=function(){});try{var a=(null===(o=this._mp)||void 0===o?void 0:o.onAppShow)||(null===(n=this._mp)||void 0===n?void 0:n.onShow)||function(){},p=(null===(i=this._mp)||void 0===i?void 0:i.onAppHide)||(null===(r=this._mp)||void 0===r?void 0:r.onHide)||function(){};a((function(){s._consoleLog&&console.log("[XLOG] onAppShow"),t()})),p((function(){s._consoleLog&&console.log("[XLOG] onAppHide"),e()}))}catch(t){console.error("[XLOG] onAppShow or onAppHide error",t)}},t.prototype._getStorage=function(t){var e;try{return null===(e=this._mp)||void 0===e?void 0:e.getStorageSync("XYZ_LOG_".concat(t))}catch(t){console.error("[XLOG] getStorageSync error",t)}},t.prototype._setStorage=function(t,e){var o;try{null===(o=this._mp)||void 0===o||o.setStorageSync("XYZ_LOG_".concat(t),e)}catch(t){console.error("[XLOG] setStorageSync error",t)}},t.prototype._getBatchId=function(){var t=this._getStorage("BATCH_ID");return t&&!this._isColdStartUp||(t=function(t,e){void 0===t&&(t=18),void 0===e&&(e=0);for(var o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=[],i=Math.random,r=t,s=e||o.length,a=0;a<r;a++)n[a]=o[0|i()*s];return n.join("")}(),this._setStorage("BATCH_ID",t)),t},t.prototype._coldStartUp=function(){var t=this;this._getNetworkType().then((function(e){t._updateCommonParams({network:e}),t._open({openway:0})}))},t.prototype._getApis=function(t){var o=this._isPro?{open:"webopen-inside.tt.cn",event:"webevent-inside.tt.cn",act:"webact-inside.tt.cn",ad:"webadv-inside.tt.cn",online:"webact-inside.tt.cn"}:{open:"test-webopen-inside.tt.cn",event:"test-webevent-inside.tt.cn",act:"test-webact-inside.tt.cn",ad:"test-webadv-inside.tt.cn",online:"test-webact-inside.tt.cn"},n=e(e({},o),t);return{openUrl:"https://".concat(n.open,"/gamefunction_logs/applet/open"),eventUrl:"https://".concat(n.event,"/gamefunction_logs/applet/event"),actUrl:"https://".concat(n.act,"/gamefunction_logs/applet/activity"),adUrl:"https://".concat(n.ad,"/gamefunction_logs/applet/adv"),onlineUrl:"https://".concat(n.online,"/gamefunction_logs/applet/onlineTime")}},t.prototype._cacheCommonParams=function(t){this._setStorage("COMMON_PARAMS",JSON.stringify(t))},t.prototype._getInitParams=function(){return{platform:this._platform,appcqid:s,appqid:s+o(),os:this._systemInfo.platform,osversion:this._systemInfo.system&&this._systemInfo.system.split(" ")[1],device:this._systemInfo.model,devicebrand:this._systemInfo.brand,pixel:this._systemInfo.screenWidth+"*"+this._systemInfo.screenHeight,userinfo:this._getUserInfo()}},t.prototype._initCommonParams=function(t){var o=this._getInitParams(),i=this._getStorage("COMMON_PARAMS");i&&(o=e(e({},o),JSON.parse(i))),o=t?n(o,t):o,this._updateCommonParams(e(e({},o),{obatchid:this._getBatchId()}))},t.prototype._getNetworkType=function(){var t=this;return new Promise((function(e){var o;try{null===(o=t._mp)||void 0===o||o.getNetworkType({success:function(t){e(t.networkType)},fail:function(){e("none")}})}catch(t){e("none"),console.error("[XLOG] getNetworkType error",t)}}))},t.prototype._getUserInfo=function(t){var o={};if(t)try{o=JSON.parse(t)}catch(t){console.error('[XLOG] The parameter "userinfo" is not in JSON string format!')}var n={};if(this.commonParams.userinfo)try{n=JSON.parse(this.commonParams.userinfo)}catch(t){console.error("[XLOG] parse error",t)}return JSON.stringify(e(e(e({},this._extraInfo),n),o))},t.prototype._filterParams=function(t){var e={};if(t){var o=["openid","unionid","accid","apptypeid","appcqid","srcqid","appver","userinfo"];for(var n in t){var i=t[n];o.includes(n)&&i&&(e[n]=i)}}return e},t.prototype.setParams=function(t){if(t){this._consoleLog&&console.log("[XLOG] setParams",t);var e=this._commonParams.openid,o=this._commonParams.unionid;t=this._filterParams(t),this._updateCommonParams(t),(t.openid&&t.openid!==e||t.unionid&&t.unionid!==o)&&this._open({isreturn:t.openid?1:2,openway:0})}},t.prototype._updateCommonParams=function(t){this._consoleLog&&console.log("[XLOG] _updateCommonParams",t),t.userinfo&&(t.userinfo=this._getUserInfo(t.userinfo)),t.appcqid&&(t.appqid=t.appcqid+o()),t.appver&&(t.appverint=function(t){try{return t&&"string"==typeof t?t.split(".").map((function(t){return 1===t.length?"0"+t:t})).join(""):""}catch(e){return console.error('[transferVersion] ver("'.concat(t,'")格式异常:'),e),""}}(t.appver)),this._commonParams=n(this._commonParams,t),this._cacheCommonParams(this._commonParams)},t.prototype._getAppqid=function(){return this._commonParams.appcqid+o()},t.prototype._request=function(t,e,o){var n=this;return void 0===o&&(o="application/x-www-form-urlencoded"),new Promise((function(i,r){var s;try{null===(s=n._mp)||void 0===s||s.request({url:t,data:e,method:"POST",header:{"content-type":o},success:function(o){n._consoleLog&&console.log("[XLOG] SUCCESS: ".concat(t),e,o),i(o)},fail:function(o){n._consoleLog&&console.log("[XLOG] FAIL: ".concat(t),e,o),r(o)}})}catch(t){console.error("[XLOG] request error",t)}}))},t.prototype.open=function(t){this._open({querystring:t.querystring,isreturn:3,openway:0})},t.prototype._open=function(t){var o,n,i=null;try{i=((null===(o=this._mp)||void 0===o?void 0:o.getEnterOptionsSync)||(null===(n=this._mp)||void 0===n?void 0:n.getLaunchOptionsSync)||function(){})()}catch(t){console.error("[XLOG] getEnterOptionsSync error",t)}if((null==i?void 0:i.query)?this._updateCommonParams({userinfo:JSON.stringify({querystring:e(e({},i.query),t.querystring)})}):this._updateCommonParams({userinfo:JSON.stringify({querystring:t.querystring})}),this._sendOpenLog){var s=e(e({},this._commonParams),{appqid:this._getAppqid(),wakeway:t.wakeway||(null==i?void 0:i.scene)||"",openway:t.openway,isreturn:t.isreturn||0,xmlog:r});this._consoleLog&&console.log("[XLOG] PARAMS(OPEN)",s),this._request(this._openUrl,s)}},t.prototype.event=function(t){var o=e(e({},this._commonParams),{appqid:this._getAppqid(),event1:t.event1||"",event2:t.event2||"",event3:t.event3||"",event4:t.event4||"",value1:t.value1||"",value2:t.value2||"",value3:t.value3||"",value4:t.value4||""});this._consoleLog&&console.log("[XLOG] PARAMS(EVENT)",o),this._request(this._eventUrl,o)},t.prototype.act=function(t){var o=e(e({},this._commonParams),{appqid:this._getAppqid(),actentryid:t.actentryid||"",subactid:t.subactid||"",type:t.type||"",custom:t.custom||"",batchid:t.batchid||""});this._consoleLog&&console.log("[XLOG] PARAMS(ACT)",o),this._request(this._actUrl,o)},t.prototype.ad=function(t){var o=e(e({},this._commonParams),{appqid:this._getAppqid(),type:t.type||"",code:t.code||"",codeinfo:t.codeinfo||"",pagetype:t.pagetype||"",gametype:t.gametype||"",adslot:t.adslot||"",adunitid:t.adunitid||"",adbatchid:t.adbatchid||"",ecpm:t.ecpm||""});this._consoleLog&&console.log("[XLOG] PARAMS(AD)",o),this._request(this._adUrl,o,"application/json")},t.prototype._sendOnline=function(){var t=Date.now(),o=e(e({},this._commonParams),{appqid:this._getAppqid(),onlinetime:"".concat(t-this._startTime),endtime:t.toString(),starttime:this._startTime.toString()});this._online([o])},t.prototype._setOnlineBatchData=function(t){this._setStorage("ONLINE_BACH_DATA",t)},t.prototype._getOnlineBatchData=function(){return this._getStorage("ONLINE_BACH_DATA")},t.prototype._clearOnlineBatchData=function(){this._setStorage("ONLINE_BACH_DATA","")},t.prototype._online=function(t){var e=this;this._consoleLog&&console.log("[XLOG] PARAMS(ONLINE)",t),this._clearOnlineBatchData(),this._request(this._onlineUrl,{batch:JSON.stringify(t)}).catch((function(o){e._setOnlineBatchData(t)}))},t}();t.XLog=a,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
6
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mp={})}(this,(function(t){"use strict";var e=function(){return e=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},e.apply(this,arguments)};function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{p(o.next(t))}catch(t){r(t)}}function a(t){try{p(o.throw(t))}catch(t){r(t)}}function p(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}p((o=o.apply(t,e||[])).next())}))}function o(t,e){var n,o,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,o=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],o=0}finally{n=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}function i(){var t=new Date,e=t.getFullYear().toString(),n=(t.getMonth()+1).toString(),o=t.getDate().toString();return(e=e.toString().substr(-2))+(n=Number(n)<10?"0"+n:n)+(o=Number(o)<10?"0"+o:o)}function r(t,n){var o=e({},t),i=e({},n);return Object.keys(o).forEach((function(t){i[t]||delete i[t]})),e(e({},o),i)}var s,a="4.0.0",p="organic";t.EGender=void 0,(s=t.EGender||(t.EGender={}))[s.Unknown=0]="Unknown",s[s.Male=1]="Male",s[s.Female=2]="Female";var c=function(){function t(t){var e,n=t.domain,o=t.commonParams,i=t.isPro,r=void 0===i||i,s=t.sendOpenLog,p=void 0===s||s,c=t.consoleLog,u=void 0===c||c;this.version=a,this.buildDate="3/7/2025, 6:00:43 PM",this._openUrl="",this._eventUrl="",this._actUrl="",this._adUrl="",this._onlineUrl="",this._businessDomain="",this._startTime=Date.now(),this._commonParams={},this._isPro=!0,this._sendOpenLog=!0,this._isColdStartUp=!0,this._systemInfo={},this._mp={},this._consoleLog=!0,this._isPro=r,this._sendOpenLog=p,this._consoleLog=u;var l=this._getApis(n),h=l.openUrl,d=l.eventUrl,f=l.actUrl,m=l.adUrl,_=l.onlineUrl;this._openUrl=h,this._eventUrl=d,this._actUrl=f,this._adUrl=m,this._onlineUrl=_,this._businessDomain=this._isPro?"https://applet-xx.mop.com":"https://test-applet-xx.mop.com";var y,g=this._getMp(),v=g.mp,O=g.platform;this._mp=v,this._platform=O,!v||(y=v)&&0===Object.keys(y).length&&y.constructor===Object?console.error("[XLOG] 日志SDK初始化失败,当前环境为非小程序环境!"):this._consoleLog&&console.log("[XLOG] 小程序对象:",v);try{this._systemInfo=(null===(e=this._mp)||void 0===e?void 0:e.getSystemInfoSync())||{}}catch(t){console.error("[XLOG] getSystemInfoSync error",t)}this._extraInfo={language:this._systemInfo.language,wxVersion:this._systemInfo.version,SDKVersion:this._systemInfo.SDKVersion,benchmarkLevel:this._systemInfo.benchmarkLevel||-1,theme:this._systemInfo.theme,pixelRatio:this._systemInfo.pixelRatio},this._init(o)}return Object.defineProperty(t.prototype,"commonParams",{get:function(){return this._commonParams},enumerable:!1,configurable:!0}),t.prototype._getLaunchOptions=function(){var t,e,n=null;try{n=((null===(t=this._mp)||void 0===t?void 0:t.getEnterOptionsSync)||(null===(e=this._mp)||void 0===e?void 0:e.getLaunchOptionsSync)||function(){})()}catch(t){console.error("[XLOG] getEnterOptionsSync or getLaunchOptionsSync error",t)}return n},t.prototype._updateQuerystring=function(t,n){void 0===t&&(t=null),void 0===n&&(n={}),(null==t?void 0:t.query)?this._updateCommonParams({srcqid:t.query.channel||"",userinfo:JSON.stringify({querystring:e(e({},t.query),n)})}):this._updateCommonParams({userinfo:JSON.stringify({querystring:n})})},t.prototype._init=function(t){var e=this;this._initCommonParams(this._filterParams(t));var n=this._getLaunchOptions();this._updateQuerystring(n),this._coldStartUp(),this._visibilityChange((function(){e._isColdStartUp||e._getNetworkType().then((function(t){e._updateCommonParams({network:t}),e._open({openway:1})})),e._startTime=Date.now();var t=e._getOnlineBatchData();t&&e._online(t)}),(function(){e._isColdStartUp=!1,e._open({openway:5}),e._sendOnline()}))},t.prototype._getMp=function(){var t={mp:null,platform:7};return"undefined"!=typeof tt?(t.mp=tt,t.platform=2):"undefined"!=typeof ks?(t.mp=ks,t.platform=3):"undefined"!=typeof swan?(t.mp=swan,t.platform=4):"undefined"!=typeof qq?(t.mp=qq,t.platform=5):"undefined"!=typeof wx?(t.mp=wx,t.platform=1):"undefined"!=typeof my?t.mp=my:"undefined"!=typeof jd&&(t.mp=jd),t},t.prototype._visibilityChange=function(t,e){var n,o,i,r,s=this;void 0===t&&(t=function(){}),void 0===e&&(e=function(){});try{var a=(null===(n=this._mp)||void 0===n?void 0:n.onAppShow)||(null===(o=this._mp)||void 0===o?void 0:o.onShow)||function(){},p=(null===(i=this._mp)||void 0===i?void 0:i.onAppHide)||(null===(r=this._mp)||void 0===r?void 0:r.onHide)||function(){};a((function(){s._consoleLog&&console.log("[XLOG] onAppShow"),t()})),p((function(){s._consoleLog&&console.log("[XLOG] onAppHide"),e()}))}catch(t){console.error("[XLOG] onAppShow or onAppHide error",t)}},t.prototype._getStorage=function(t){var e;try{return null===(e=this._mp)||void 0===e?void 0:e.getStorageSync("XYZ_LOG_".concat(t))}catch(t){console.error("[XLOG] getStorageSync error",t)}},t.prototype._setStorage=function(t,e){var n;try{null===(n=this._mp)||void 0===n||n.setStorageSync("XYZ_LOG_".concat(t),e)}catch(t){console.error("[XLOG] setStorageSync error",t)}},t.prototype._getBatchId=function(){var t=this._getStorage("BATCH_ID");return t&&!this._isColdStartUp||(t=function(t,e){void 0===t&&(t=18),void 0===e&&(e=0);for(var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),o=[],i=Math.random,r=t,s=e||n.length,a=0;a<r;a++)o[a]=n[0|i()*s];return o.join("")}(),this._setStorage("BATCH_ID",t)),t},t.prototype._coldStartUp=function(){var t=this;this._getNetworkType().then((function(e){t._updateCommonParams({network:e}),t._open({openway:0})}))},t.prototype._getApis=function(t){var n=this._isPro?{open:"webopen-inside.tt.cn",event:"webevent-inside.tt.cn",act:"webact-inside.tt.cn",ad:"webadv-inside.tt.cn",online:"webact-inside.tt.cn"}:{open:"test-webopen-inside.tt.cn",event:"test-webevent-inside.tt.cn",act:"test-webact-inside.tt.cn",ad:"test-webadv-inside.tt.cn",online:"test-webact-inside.tt.cn"},o=e(e({},n),t);return{openUrl:"https://".concat(o.open,"/gamefunction_logs/applet/open"),eventUrl:"https://".concat(o.event,"/gamefunction_logs/applet/event"),actUrl:"https://".concat(o.act,"/gamefunction_logs/applet/activity"),adUrl:"https://".concat(o.ad,"/gamefunction_logs/applet/adv"),onlineUrl:"https://".concat(o.online,"/gamefunction_logs/applet/onlineTime")}},t.prototype._cacheCommonParams=function(t){this._setStorage("COMMON_PARAMS",JSON.stringify(t))},t.prototype._getInitParams=function(){var t,e=(null===(t=this._systemInfo.system)||void 0===t?void 0:t.includes(" "))?this._systemInfo.system.split(" ")[1]:this._systemInfo.system;return{platform:this._platform,appcqid:p,appqid:p+i(),os:this._systemInfo.platform,osversion:e,device:this._systemInfo.model,devicebrand:this._systemInfo.brand,pixel:this._systemInfo.screenWidth+"*"+this._systemInfo.screenHeight,userinfo:this._getUserInfo()}},t.prototype._initCommonParams=function(t){var n=this._getInitParams(),o=this._getStorage("COMMON_PARAMS");o&&(n=e(e({},n),JSON.parse(o))),n=t?r(n,t):n,this._updateCommonParams(e(e({},n),{obatchid:this._getBatchId()}))},t.prototype._getNetworkType=function(){var t=this;return new Promise((function(e){var n;try{null===(n=t._mp)||void 0===n||n.getNetworkType({success:function(t){e(t.networkType)},fail:function(){e("none")}})}catch(t){e("none"),console.error("[XLOG] getNetworkType error",t)}}))},t.prototype._getUserInfo=function(t){var n={};if(t)try{n=JSON.parse(t)}catch(e){console.error('[XLOG] The parameter "userinfo" is not in JSON string format: ',t)}var o={};if(this.commonParams.userinfo)try{o=JSON.parse(this.commonParams.userinfo)}catch(t){console.error("[XLOG] parse error",t)}return JSON.stringify(e(e(e({},this._extraInfo),o),n))},t.prototype._filterParams=function(t){var e={};if(t){var n=["openid","unionid","accid","apptypeid","appsubid","appcqid","srcqid","appver","userinfo"];for(var o in t){var i=t[o];n.includes(o)&&i&&(e[o]=i)}}return e},t.prototype.setParams=function(t){if(t){this._consoleLog&&console.log("[XLOG] setParams",t);var e=this._commonParams.openid,n=this._commonParams.unionid;t=this._filterParams(t),this._updateCommonParams(t),(t.openid&&t.openid!==e||t.unionid&&t.unionid!==n)&&this._open({isreturn:t.openid?1:2,openway:0})}},t.prototype._updateCommonParams=function(t){this._consoleLog&&console.log("[XLOG] _updateCommonParams",t),t.userinfo&&(t.appsubid&&(t.userinfo=JSON.stringify(e(e({},JSON.parse(t.userinfo)),{appsubid:t.appsubid}))),t.userinfo=this._getUserInfo(t.userinfo)),t.appcqid&&(t.appqid=t.appcqid+i()),t.appver&&(t.appverint=function(t){try{return t&&"string"==typeof t?t.split(".").map((function(t){return 1===t.length?"0"+t:t})).join(""):""}catch(e){return console.error('[transferVersion] ver("'.concat(t,'")格式异常:'),e),""}}(t.appver)),this._commonParams=r(this._commonParams,t),this._cacheCommonParams(this._commonParams)},t.prototype._getAppqid=function(){return this._commonParams.appcqid+i()},t.prototype._request=function(t,e,n){var o=this;return void 0===n&&(n="application/x-www-form-urlencoded"),new Promise((function(i,r){var s;try{null===(s=o._mp)||void 0===s||s.request({url:t,data:e,method:"POST",header:{"content-type":n},success:function(n){o._consoleLog&&console.log("[XLOG] SUCCESS: ".concat(t),e,n),i(n)},fail:function(n){o._consoleLog&&console.log("[XLOG] FAIL: ".concat(t),e,n),r(n)}})}catch(t){console.error("[XLOG] request error",t),r(t)}}))},t.prototype.open=function(t){this._open({querystring:t.querystring,isreturn:3,openway:0,manual:!0})},t.prototype._open=function(t){if(this._sendOpenLog||t.manual){var n=this._getLaunchOptions();this._updateQuerystring(n,t.querystring);var o=e(e({},this._commonParams),{appqid:this._getAppqid(),wakeway:t.wakeway||(null==n?void 0:n.scene)||"",openway:t.openway,isreturn:t.isreturn||0,xmlog:a});this._consoleLog&&console.log("[XLOG] PARAMS(OPEN)",o),this._request(this._openUrl,o)}},t.prototype.event=function(t){var n=e(e({},this._commonParams),{appqid:this._getAppqid(),event1:t.event1||"",event2:t.event2||"",event3:t.event3||"",event4:t.event4||"",value1:t.value1||"",value2:t.value2||"",value3:t.value3||"",value4:t.value4||""});this._consoleLog&&console.log("[XLOG] PARAMS(EVENT)",n),this._request(this._eventUrl,n)},t.prototype.act=function(t){var n=e(e({},this._commonParams),{appqid:this._getAppqid(),actentryid:t.actentryid||"",subactid:t.subactid||"",type:t.type||"",custom:t.custom||"",batchid:t.batchid||""});this._consoleLog&&console.log("[XLOG] PARAMS(ACT)",n),this._request(this._actUrl,n)},t.prototype.ad=function(t){var n=e(e({},this._commonParams),{appqid:this._getAppqid(),type:t.type||"",code:t.code||"",codeinfo:t.codeinfo||"",pagetype:t.pagetype||"",gametype:t.gametype||"",adslot:t.adslot||"",adunitid:t.adunitid||"",adbatchid:t.adbatchid||"",ecpm:t.ecpm||""});this._consoleLog&&console.log("[XLOG] PARAMS(AD)",n),this._request(this._adUrl,n,"application/json")},t.prototype.code2session=function(t){return n(this,void 0,void 0,(function(){var e,n;return o(this,(function(o){switch(o.label){case 0:return e="",1===this._platform?e="wx/":3===this._platform&&(e="ks/"),n="".concat(this._businessDomain,"/AppletUtils/").concat(e,"code2session"),[4,this._request(n,{appTypeId:t.apptypeid,code:t.code,testNet:t.testNet},"application/json")];case 1:return[2,o.sent().data]}}))}))},t.prototype.getSubsidy=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/subsidy"),{apptypeid:t.apptypeid,os:this._systemInfo.platform,openId:t.openId},"application/json")];case 1:return[2,e.sent().data]}}))}))},t.prototype.getUserProps=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/userProps"),{appTypeId:t.apptypeid,openId:t.openId},"application/json")];case 1:return[2,e.sent().data]}}))}))},t.prototype.checkOrder=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/chkOrder"),{appTypeId:t.apptypeid,os:this._systemInfo.platform,openId:t.openId,orderId:t.orderId},"application/json")];case 1:return[2,e.sent().data]}}))}))},t.prototype.createOrder=function(t){return n(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/crtOrder"),{appTypeId:t.apptypeid,os:this._systemInfo.platform,openId:t.openId,productId:t.productId,payPlatform:t.payPlatform},"application/json")];case 1:return[2,e.sent().data]}}))}))},t.prototype._sendOnline=function(){var t=Date.now(),n=e(e({},this._commonParams),{appqid:this._getAppqid(),onlinetime:"".concat(t-this._startTime),endtime:t.toString(),starttime:this._startTime.toString()});this._online([n])},t.prototype._setOnlineBatchData=function(t){this._setStorage("ONLINE_BACH_DATA",t)},t.prototype._getOnlineBatchData=function(){return this._getStorage("ONLINE_BACH_DATA")},t.prototype._clearOnlineBatchData=function(){this._setStorage("ONLINE_BACH_DATA","")},t.prototype._online=function(t){var e=this;this._consoleLog&&console.log("[XLOG] PARAMS(ONLINE)",t),this._clearOnlineBatchData(),this._request(this._onlineUrl,{batch:JSON.stringify(t)}).catch((function(n){e._setOnlineBatchData(t)}))},t}();t.XLog=c,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
7
7
|
//# sourceMappingURL=mp.min.js.map
|
package/dist/mp.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @xyz-fe/log
|
|
2
|
+
* @xyz-fe/log v4.0.0
|
|
3
3
|
* (c) lizhigao <lizhigao@021.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var t=function(){return t=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(){var t=new Date,e=t.getFullYear().toString(),o=(t.getMonth()+1).toString(),n=t.getDate().toString();return(e=e.toString().substr(-2))+(o=Number(o)<10?"0"+o:o)+(n=Number(n)<10?"0"+n:n)}function o(e,o){var n=t({},e),i=t({},o);return Object.keys(n).forEach((function(t){i[t]||delete i[t]})),t(t({},n),i)}var n;!function(t){t[t.Unknown=0]="Unknown",t[t.Male=1]="Male",t[t.Female=2]="Female"}(n||(n={}));var i=function(){function n(t){var e,o=t.domain,n=t.commonParams,i=t.isPro,r=void 0===i||i,s=t.sendOpenLog,a=void 0===s||s,p=t.consoleLog,c=void 0===p||p;this.version="3.8.1",this.buildDate="2/20/2025, 10:28:18 AM",this._openUrl="",this._eventUrl="",this._actUrl="",this._adUrl="",this._onlineUrl="",this._startTime=Date.now(),this._commonParams={},this._isPro=!0,this._sendOpenLog=!0,this._isColdStartUp=!0,this._systemInfo={},this._mp={},this._consoleLog=!0,this._isPro=r,this._sendOpenLog=a,this._consoleLog=c;var l=this._getApis(o),h=l.openUrl,m=l.eventUrl,u=l.actUrl,_=l.adUrl,d=l.onlineUrl;this._openUrl=h,this._eventUrl=m,this._actUrl=u,this._adUrl=_,this._onlineUrl=d;var f,g=this._getMp(),y=g.mp,v=g.platform;this._mp=y,this._platform=v,!y||(f=y)&&0===Object.keys(f).length&&f.constructor===Object?console.error("[XLOG] 日志SDK初始化失败,当前环境为非小程序环境!"):this._consoleLog&&console.log("[XLOG] 小程序对象:",y);try{this._systemInfo=(null===(e=this._mp)||void 0===e?void 0:e.getSystemInfoSync())||{}}catch(t){console.error("[XLOG] getSystemInfoSync error",t)}this._extraInfo={language:this._systemInfo.language,wxVersion:this._systemInfo.version,SDKVersion:this._systemInfo.SDKVersion,benchmarkLevel:this._systemInfo.benchmarkLevel||-1,theme:this._systemInfo.theme},this._init(n)}return Object.defineProperty(n.prototype,"commonParams",{get:function(){return this._commonParams},enumerable:!1,configurable:!0}),n.prototype._init=function(t){var e=this;this._initCommonParams(this._filterParams(t)),this._coldStartUp(),this._visibilityChange((function(){e._isColdStartUp||e._getNetworkType().then((function(t){e._updateCommonParams({network:t}),e._open({openway:1})})),e._startTime=Date.now();var t=e._getOnlineBatchData();t&&e._online(t)}),(function(){e._isColdStartUp=!1,e._open({openway:5}),e._sendOnline()}))},n.prototype._getMp=function(){var t={mp:null,platform:7};return"undefined"!=typeof tt?(t.mp=tt,t.platform=2):"undefined"!=typeof ks?(t.mp=ks,t.platform=3):"undefined"!=typeof swan?(t.mp=swan,t.platform=4):"undefined"!=typeof qq?(t.mp=qq,t.platform=5):"undefined"!=typeof wx?(t.mp=wx,t.platform=1):"undefined"!=typeof my?t.mp=my:"undefined"!=typeof jd&&(t.mp=jd),t},n.prototype._visibilityChange=function(t,e){var o,n,i,r,s=this;void 0===t&&(t=function(){}),void 0===e&&(e=function(){});try{var a=(null===(o=this._mp)||void 0===o?void 0:o.onAppShow)||(null===(n=this._mp)||void 0===n?void 0:n.onShow)||function(){},p=(null===(i=this._mp)||void 0===i?void 0:i.onAppHide)||(null===(r=this._mp)||void 0===r?void 0:r.onHide)||function(){};a((function(){s._consoleLog&&console.log("[XLOG] onAppShow"),t()})),p((function(){s._consoleLog&&console.log("[XLOG] onAppHide"),e()}))}catch(t){console.error("[XLOG] onAppShow or onAppHide error",t)}},n.prototype._getStorage=function(t){var e;try{return null===(e=this._mp)||void 0===e?void 0:e.getStorageSync("XYZ_LOG_".concat(t))}catch(t){console.error("[XLOG] getStorageSync error",t)}},n.prototype._setStorage=function(t,e){var o;try{null===(o=this._mp)||void 0===o||o.setStorageSync("XYZ_LOG_".concat(t),e)}catch(t){console.error("[XLOG] setStorageSync error",t)}},n.prototype._getBatchId=function(){var t=this._getStorage("BATCH_ID");return t&&!this._isColdStartUp||(t=function(t,e){void 0===t&&(t=18),void 0===e&&(e=0);for(var o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=[],i=Math.random,r=t,s=e||o.length,a=0;a<r;a++)n[a]=o[0|i()*s];return n.join("")}(),this._setStorage("BATCH_ID",t)),t},n.prototype._coldStartUp=function(){var t=this;this._getNetworkType().then((function(e){t._updateCommonParams({network:e}),t._open({openway:0})}))},n.prototype._getApis=function(e){var o=this._isPro?{open:"webopen-inside.tt.cn",event:"webevent-inside.tt.cn",act:"webact-inside.tt.cn",ad:"webadv-inside.tt.cn",online:"webact-inside.tt.cn"}:{open:"test-webopen-inside.tt.cn",event:"test-webevent-inside.tt.cn",act:"test-webact-inside.tt.cn",ad:"test-webadv-inside.tt.cn",online:"test-webact-inside.tt.cn"},n=t(t({},o),e);return{openUrl:"https://".concat(n.open,"/gamefunction_logs/applet/open"),eventUrl:"https://".concat(n.event,"/gamefunction_logs/applet/event"),actUrl:"https://".concat(n.act,"/gamefunction_logs/applet/activity"),adUrl:"https://".concat(n.ad,"/gamefunction_logs/applet/adv"),onlineUrl:"https://".concat(n.online,"/gamefunction_logs/applet/onlineTime")}},n.prototype._cacheCommonParams=function(t){this._setStorage("COMMON_PARAMS",JSON.stringify(t))},n.prototype._getInitParams=function(){return{platform:this._platform,appcqid:"organic",appqid:"organic"+e(),os:this._systemInfo.platform,osversion:this._systemInfo.system&&this._systemInfo.system.split(" ")[1],device:this._systemInfo.model,devicebrand:this._systemInfo.brand,pixel:this._systemInfo.screenWidth+"*"+this._systemInfo.screenHeight,userinfo:this._getUserInfo()}},n.prototype._initCommonParams=function(e){var n=this._getInitParams(),i=this._getStorage("COMMON_PARAMS");i&&(n=t(t({},n),JSON.parse(i))),n=e?o(n,e):n,this._updateCommonParams(t(t({},n),{obatchid:this._getBatchId()}))},n.prototype._getNetworkType=function(){var t=this;return new Promise((function(e){var o;try{null===(o=t._mp)||void 0===o||o.getNetworkType({success:function(t){e(t.networkType)},fail:function(){e("none")}})}catch(t){e("none"),console.error("[XLOG] getNetworkType error",t)}}))},n.prototype._getUserInfo=function(e){var o={};if(e)try{o=JSON.parse(e)}catch(t){console.error('[XLOG] The parameter "userinfo" is not in JSON string format!')}var n={};if(this.commonParams.userinfo)try{n=JSON.parse(this.commonParams.userinfo)}catch(t){console.error("[XLOG] parse error",t)}return JSON.stringify(t(t(t({},this._extraInfo),n),o))},n.prototype._filterParams=function(t){var e={};if(t){var o=["openid","unionid","accid","apptypeid","appcqid","srcqid","appver","userinfo"];for(var n in t){var i=t[n];o.includes(n)&&i&&(e[n]=i)}}return e},n.prototype.setParams=function(t){if(t){this._consoleLog&&console.log("[XLOG] setParams",t);var e=this._commonParams.openid,o=this._commonParams.unionid;t=this._filterParams(t),this._updateCommonParams(t),(t.openid&&t.openid!==e||t.unionid&&t.unionid!==o)&&this._open({isreturn:t.openid?1:2,openway:0})}},n.prototype._updateCommonParams=function(t){this._consoleLog&&console.log("[XLOG] _updateCommonParams",t),t.userinfo&&(t.userinfo=this._getUserInfo(t.userinfo)),t.appcqid&&(t.appqid=t.appcqid+e()),t.appver&&(t.appverint=function(t){try{return t&&"string"==typeof t?t.split(".").map((function(t){return 1===t.length?"0"+t:t})).join(""):""}catch(e){return console.error('[transferVersion] ver("'.concat(t,'")格式异常:'),e),""}}(t.appver)),this._commonParams=o(this._commonParams,t),this._cacheCommonParams(this._commonParams)},n.prototype._getAppqid=function(){return this._commonParams.appcqid+e()},n.prototype._request=function(t,e,o){var n=this;return void 0===o&&(o="application/x-www-form-urlencoded"),new Promise((function(i,r){var s;try{null===(s=n._mp)||void 0===s||s.request({url:t,data:e,method:"POST",header:{"content-type":o},success:function(o){n._consoleLog&&console.log("[XLOG] SUCCESS: ".concat(t),e,o),i(o)},fail:function(o){n._consoleLog&&console.log("[XLOG] FAIL: ".concat(t),e,o),r(o)}})}catch(t){console.error("[XLOG] request error",t)}}))},n.prototype.open=function(t){this._open({querystring:t.querystring,isreturn:3,openway:0})},n.prototype._open=function(e){var o,n,i=null;try{i=((null===(o=this._mp)||void 0===o?void 0:o.getEnterOptionsSync)||(null===(n=this._mp)||void 0===n?void 0:n.getLaunchOptionsSync)||function(){})()}catch(t){console.error("[XLOG] getEnterOptionsSync error",t)}if((null==i?void 0:i.query)?this._updateCommonParams({userinfo:JSON.stringify({querystring:t(t({},i.query),e.querystring)})}):this._updateCommonParams({userinfo:JSON.stringify({querystring:e.querystring})}),this._sendOpenLog){var r=t(t({},this._commonParams),{appqid:this._getAppqid(),wakeway:e.wakeway||(null==i?void 0:i.scene)||"",openway:e.openway,isreturn:e.isreturn||0,xmlog:"3.8.1"});this._consoleLog&&console.log("[XLOG] PARAMS(OPEN)",r),this._request(this._openUrl,r)}},n.prototype.event=function(e){var o=t(t({},this._commonParams),{appqid:this._getAppqid(),event1:e.event1||"",event2:e.event2||"",event3:e.event3||"",event4:e.event4||"",value1:e.value1||"",value2:e.value2||"",value3:e.value3||"",value4:e.value4||""});this._consoleLog&&console.log("[XLOG] PARAMS(EVENT)",o),this._request(this._eventUrl,o)},n.prototype.act=function(e){var o=t(t({},this._commonParams),{appqid:this._getAppqid(),actentryid:e.actentryid||"",subactid:e.subactid||"",type:e.type||"",custom:e.custom||"",batchid:e.batchid||""});this._consoleLog&&console.log("[XLOG] PARAMS(ACT)",o),this._request(this._actUrl,o)},n.prototype.ad=function(e){var o=t(t({},this._commonParams),{appqid:this._getAppqid(),type:e.type||"",code:e.code||"",codeinfo:e.codeinfo||"",pagetype:e.pagetype||"",gametype:e.gametype||"",adslot:e.adslot||"",adunitid:e.adunitid||"",adbatchid:e.adbatchid||"",ecpm:e.ecpm||""});this._consoleLog&&console.log("[XLOG] PARAMS(AD)",o),this._request(this._adUrl,o,"application/json")},n.prototype._sendOnline=function(){var e=Date.now(),o=t(t({},this._commonParams),{appqid:this._getAppqid(),onlinetime:"".concat(e-this._startTime),endtime:e.toString(),starttime:this._startTime.toString()});this._online([o])},n.prototype._setOnlineBatchData=function(t){this._setStorage("ONLINE_BACH_DATA",t)},n.prototype._getOnlineBatchData=function(){return this._getStorage("ONLINE_BACH_DATA")},n.prototype._clearOnlineBatchData=function(){this._setStorage("ONLINE_BACH_DATA","")},n.prototype._online=function(t){var e=this;this._consoleLog&&console.log("[XLOG] PARAMS(ONLINE)",t),this._clearOnlineBatchData(),this._request(this._onlineUrl,{batch:JSON.stringify(t)}).catch((function(o){e._setOnlineBatchData(t)}))},n}();export{n as EGender,i as XLog};
|
|
6
|
+
var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{p(o.next(t))}catch(t){r(t)}}function a(t){try{p(o.throw(t))}catch(t){r(t)}}function p(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}p((o=o.apply(t,e||[])).next())}))}function n(t,e){var n,o,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,o=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(t){r=[6,t],o=0}finally{n=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}function o(){var t=new Date,e=t.getFullYear().toString(),n=(t.getMonth()+1).toString(),o=t.getDate().toString();return(e=e.toString().substr(-2))+(n=Number(n)<10?"0"+n:n)+(o=Number(o)<10?"0"+o:o)}function i(e,n){var o=t({},e),i=t({},n);return Object.keys(o).forEach((function(t){i[t]||delete i[t]})),t(t({},o),i)}var r;!function(t){t[t.Unknown=0]="Unknown",t[t.Male=1]="Male",t[t.Female=2]="Female"}(r||(r={}));var s=function(){function r(t){var e,n=t.domain,o=t.commonParams,i=t.isPro,r=void 0===i||i,s=t.sendOpenLog,a=void 0===s||s,p=t.consoleLog,c=void 0===p||p;this.version="4.0.0",this.buildDate="3/7/2025, 6:00:43 PM",this._openUrl="",this._eventUrl="",this._actUrl="",this._adUrl="",this._onlineUrl="",this._businessDomain="",this._startTime=Date.now(),this._commonParams={},this._isPro=!0,this._sendOpenLog=!0,this._isColdStartUp=!0,this._systemInfo={},this._mp={},this._consoleLog=!0,this._isPro=r,this._sendOpenLog=a,this._consoleLog=c;var u=this._getApis(n),l=u.openUrl,h=u.eventUrl,d=u.actUrl,m=u.adUrl,f=u.onlineUrl;this._openUrl=l,this._eventUrl=h,this._actUrl=d,this._adUrl=m,this._onlineUrl=f,this._businessDomain=this._isPro?"https://applet-xx.mop.com":"https://test-applet-xx.mop.com";var _,y=this._getMp(),g=y.mp,v=y.platform;this._mp=g,this._platform=v,!g||(_=g)&&0===Object.keys(_).length&&_.constructor===Object?console.error("[XLOG] 日志SDK初始化失败,当前环境为非小程序环境!"):this._consoleLog&&console.log("[XLOG] 小程序对象:",g);try{this._systemInfo=(null===(e=this._mp)||void 0===e?void 0:e.getSystemInfoSync())||{}}catch(t){console.error("[XLOG] getSystemInfoSync error",t)}this._extraInfo={language:this._systemInfo.language,wxVersion:this._systemInfo.version,SDKVersion:this._systemInfo.SDKVersion,benchmarkLevel:this._systemInfo.benchmarkLevel||-1,theme:this._systemInfo.theme,pixelRatio:this._systemInfo.pixelRatio},this._init(o)}return Object.defineProperty(r.prototype,"commonParams",{get:function(){return this._commonParams},enumerable:!1,configurable:!0}),r.prototype._getLaunchOptions=function(){var t,e,n=null;try{n=((null===(t=this._mp)||void 0===t?void 0:t.getEnterOptionsSync)||(null===(e=this._mp)||void 0===e?void 0:e.getLaunchOptionsSync)||function(){})()}catch(t){console.error("[XLOG] getEnterOptionsSync or getLaunchOptionsSync error",t)}return n},r.prototype._updateQuerystring=function(e,n){void 0===e&&(e=null),void 0===n&&(n={}),(null==e?void 0:e.query)?this._updateCommonParams({srcqid:e.query.channel||"",userinfo:JSON.stringify({querystring:t(t({},e.query),n)})}):this._updateCommonParams({userinfo:JSON.stringify({querystring:n})})},r.prototype._init=function(t){var e=this;this._initCommonParams(this._filterParams(t));var n=this._getLaunchOptions();this._updateQuerystring(n),this._coldStartUp(),this._visibilityChange((function(){e._isColdStartUp||e._getNetworkType().then((function(t){e._updateCommonParams({network:t}),e._open({openway:1})})),e._startTime=Date.now();var t=e._getOnlineBatchData();t&&e._online(t)}),(function(){e._isColdStartUp=!1,e._open({openway:5}),e._sendOnline()}))},r.prototype._getMp=function(){var t={mp:null,platform:7};return"undefined"!=typeof tt?(t.mp=tt,t.platform=2):"undefined"!=typeof ks?(t.mp=ks,t.platform=3):"undefined"!=typeof swan?(t.mp=swan,t.platform=4):"undefined"!=typeof qq?(t.mp=qq,t.platform=5):"undefined"!=typeof wx?(t.mp=wx,t.platform=1):"undefined"!=typeof my?t.mp=my:"undefined"!=typeof jd&&(t.mp=jd),t},r.prototype._visibilityChange=function(t,e){var n,o,i,r,s=this;void 0===t&&(t=function(){}),void 0===e&&(e=function(){});try{var a=(null===(n=this._mp)||void 0===n?void 0:n.onAppShow)||(null===(o=this._mp)||void 0===o?void 0:o.onShow)||function(){},p=(null===(i=this._mp)||void 0===i?void 0:i.onAppHide)||(null===(r=this._mp)||void 0===r?void 0:r.onHide)||function(){};a((function(){s._consoleLog&&console.log("[XLOG] onAppShow"),t()})),p((function(){s._consoleLog&&console.log("[XLOG] onAppHide"),e()}))}catch(t){console.error("[XLOG] onAppShow or onAppHide error",t)}},r.prototype._getStorage=function(t){var e;try{return null===(e=this._mp)||void 0===e?void 0:e.getStorageSync("XYZ_LOG_".concat(t))}catch(t){console.error("[XLOG] getStorageSync error",t)}},r.prototype._setStorage=function(t,e){var n;try{null===(n=this._mp)||void 0===n||n.setStorageSync("XYZ_LOG_".concat(t),e)}catch(t){console.error("[XLOG] setStorageSync error",t)}},r.prototype._getBatchId=function(){var t=this._getStorage("BATCH_ID");return t&&!this._isColdStartUp||(t=function(t,e){void 0===t&&(t=18),void 0===e&&(e=0);for(var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),o=[],i=Math.random,r=t,s=e||n.length,a=0;a<r;a++)o[a]=n[0|i()*s];return o.join("")}(),this._setStorage("BATCH_ID",t)),t},r.prototype._coldStartUp=function(){var t=this;this._getNetworkType().then((function(e){t._updateCommonParams({network:e}),t._open({openway:0})}))},r.prototype._getApis=function(e){var n=this._isPro?{open:"webopen-inside.tt.cn",event:"webevent-inside.tt.cn",act:"webact-inside.tt.cn",ad:"webadv-inside.tt.cn",online:"webact-inside.tt.cn"}:{open:"test-webopen-inside.tt.cn",event:"test-webevent-inside.tt.cn",act:"test-webact-inside.tt.cn",ad:"test-webadv-inside.tt.cn",online:"test-webact-inside.tt.cn"},o=t(t({},n),e);return{openUrl:"https://".concat(o.open,"/gamefunction_logs/applet/open"),eventUrl:"https://".concat(o.event,"/gamefunction_logs/applet/event"),actUrl:"https://".concat(o.act,"/gamefunction_logs/applet/activity"),adUrl:"https://".concat(o.ad,"/gamefunction_logs/applet/adv"),onlineUrl:"https://".concat(o.online,"/gamefunction_logs/applet/onlineTime")}},r.prototype._cacheCommonParams=function(t){this._setStorage("COMMON_PARAMS",JSON.stringify(t))},r.prototype._getInitParams=function(){var t,e=(null===(t=this._systemInfo.system)||void 0===t?void 0:t.includes(" "))?this._systemInfo.system.split(" ")[1]:this._systemInfo.system;return{platform:this._platform,appcqid:"organic",appqid:"organic"+o(),os:this._systemInfo.platform,osversion:e,device:this._systemInfo.model,devicebrand:this._systemInfo.brand,pixel:this._systemInfo.screenWidth+"*"+this._systemInfo.screenHeight,userinfo:this._getUserInfo()}},r.prototype._initCommonParams=function(e){var n=this._getInitParams(),o=this._getStorage("COMMON_PARAMS");o&&(n=t(t({},n),JSON.parse(o))),n=e?i(n,e):n,this._updateCommonParams(t(t({},n),{obatchid:this._getBatchId()}))},r.prototype._getNetworkType=function(){var t=this;return new Promise((function(e){var n;try{null===(n=t._mp)||void 0===n||n.getNetworkType({success:function(t){e(t.networkType)},fail:function(){e("none")}})}catch(t){e("none"),console.error("[XLOG] getNetworkType error",t)}}))},r.prototype._getUserInfo=function(e){var n={};if(e)try{n=JSON.parse(e)}catch(t){console.error('[XLOG] The parameter "userinfo" is not in JSON string format: ',e)}var o={};if(this.commonParams.userinfo)try{o=JSON.parse(this.commonParams.userinfo)}catch(t){console.error("[XLOG] parse error",t)}return JSON.stringify(t(t(t({},this._extraInfo),o),n))},r.prototype._filterParams=function(t){var e={};if(t){var n=["openid","unionid","accid","apptypeid","appsubid","appcqid","srcqid","appver","userinfo"];for(var o in t){var i=t[o];n.includes(o)&&i&&(e[o]=i)}}return e},r.prototype.setParams=function(t){if(t){this._consoleLog&&console.log("[XLOG] setParams",t);var e=this._commonParams.openid,n=this._commonParams.unionid;t=this._filterParams(t),this._updateCommonParams(t),(t.openid&&t.openid!==e||t.unionid&&t.unionid!==n)&&this._open({isreturn:t.openid?1:2,openway:0})}},r.prototype._updateCommonParams=function(e){this._consoleLog&&console.log("[XLOG] _updateCommonParams",e),e.userinfo&&(e.appsubid&&(e.userinfo=JSON.stringify(t(t({},JSON.parse(e.userinfo)),{appsubid:e.appsubid}))),e.userinfo=this._getUserInfo(e.userinfo)),e.appcqid&&(e.appqid=e.appcqid+o()),e.appver&&(e.appverint=function(t){try{return t&&"string"==typeof t?t.split(".").map((function(t){return 1===t.length?"0"+t:t})).join(""):""}catch(e){return console.error('[transferVersion] ver("'.concat(t,'")格式异常:'),e),""}}(e.appver)),this._commonParams=i(this._commonParams,e),this._cacheCommonParams(this._commonParams)},r.prototype._getAppqid=function(){return this._commonParams.appcqid+o()},r.prototype._request=function(t,e,n){var o=this;return void 0===n&&(n="application/x-www-form-urlencoded"),new Promise((function(i,r){var s;try{null===(s=o._mp)||void 0===s||s.request({url:t,data:e,method:"POST",header:{"content-type":n},success:function(n){o._consoleLog&&console.log("[XLOG] SUCCESS: ".concat(t),e,n),i(n)},fail:function(n){o._consoleLog&&console.log("[XLOG] FAIL: ".concat(t),e,n),r(n)}})}catch(t){console.error("[XLOG] request error",t),r(t)}}))},r.prototype.open=function(t){this._open({querystring:t.querystring,isreturn:3,openway:0,manual:!0})},r.prototype._open=function(e){if(this._sendOpenLog||e.manual){var n=this._getLaunchOptions();this._updateQuerystring(n,e.querystring);var o=t(t({},this._commonParams),{appqid:this._getAppqid(),wakeway:e.wakeway||(null==n?void 0:n.scene)||"",openway:e.openway,isreturn:e.isreturn||0,xmlog:"4.0.0"});this._consoleLog&&console.log("[XLOG] PARAMS(OPEN)",o),this._request(this._openUrl,o)}},r.prototype.event=function(e){var n=t(t({},this._commonParams),{appqid:this._getAppqid(),event1:e.event1||"",event2:e.event2||"",event3:e.event3||"",event4:e.event4||"",value1:e.value1||"",value2:e.value2||"",value3:e.value3||"",value4:e.value4||""});this._consoleLog&&console.log("[XLOG] PARAMS(EVENT)",n),this._request(this._eventUrl,n)},r.prototype.act=function(e){var n=t(t({},this._commonParams),{appqid:this._getAppqid(),actentryid:e.actentryid||"",subactid:e.subactid||"",type:e.type||"",custom:e.custom||"",batchid:e.batchid||""});this._consoleLog&&console.log("[XLOG] PARAMS(ACT)",n),this._request(this._actUrl,n)},r.prototype.ad=function(e){var n=t(t({},this._commonParams),{appqid:this._getAppqid(),type:e.type||"",code:e.code||"",codeinfo:e.codeinfo||"",pagetype:e.pagetype||"",gametype:e.gametype||"",adslot:e.adslot||"",adunitid:e.adunitid||"",adbatchid:e.adbatchid||"",ecpm:e.ecpm||""});this._consoleLog&&console.log("[XLOG] PARAMS(AD)",n),this._request(this._adUrl,n,"application/json")},r.prototype.code2session=function(t){return e(this,void 0,void 0,(function(){var e,o;return n(this,(function(n){switch(n.label){case 0:return e="",1===this._platform?e="wx/":3===this._platform&&(e="ks/"),o="".concat(this._businessDomain,"/AppletUtils/").concat(e,"code2session"),[4,this._request(o,{appTypeId:t.apptypeid,code:t.code,testNet:t.testNet},"application/json")];case 1:return[2,n.sent().data]}}))}))},r.prototype.getSubsidy=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/subsidy"),{apptypeid:t.apptypeid,os:this._systemInfo.platform,openId:t.openId},"application/json")];case 1:return[2,e.sent().data]}}))}))},r.prototype.getUserProps=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/userProps"),{appTypeId:t.apptypeid,openId:t.openId},"application/json")];case 1:return[2,e.sent().data]}}))}))},r.prototype.checkOrder=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/chkOrder"),{appTypeId:t.apptypeid,os:this._systemInfo.platform,openId:t.openId,orderId:t.orderId},"application/json")];case 1:return[2,e.sent().data]}}))}))},r.prototype.createOrder=function(t){return e(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return[4,this._request("".concat(this._businessDomain,"/AppletUtils/pay/ks/crtOrder"),{appTypeId:t.apptypeid,os:this._systemInfo.platform,openId:t.openId,productId:t.productId,payPlatform:t.payPlatform},"application/json")];case 1:return[2,e.sent().data]}}))}))},r.prototype._sendOnline=function(){var e=Date.now(),n=t(t({},this._commonParams),{appqid:this._getAppqid(),onlinetime:"".concat(e-this._startTime),endtime:e.toString(),starttime:this._startTime.toString()});this._online([n])},r.prototype._setOnlineBatchData=function(t){this._setStorage("ONLINE_BACH_DATA",t)},r.prototype._getOnlineBatchData=function(){return this._getStorage("ONLINE_BACH_DATA")},r.prototype._clearOnlineBatchData=function(){this._setStorage("ONLINE_BACH_DATA","")},r.prototype._online=function(t){var e=this;this._consoleLog&&console.log("[XLOG] PARAMS(ONLINE)",t),this._clearOnlineBatchData(),this._request(this._onlineUrl,{batch:JSON.stringify(t)}).catch((function(n){e._setOnlineBatchData(t)}))},r}();export{r as EGender,s as XLog};
|
|
7
7
|
//# sourceMappingURL=mp.mjs.map
|
package/dist/web-hw.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface TCommonParams {
|
|
|
8
8
|
unionid?: string;
|
|
9
9
|
accid?: string;
|
|
10
10
|
apptypeid?: string;
|
|
11
|
+
appsubid?: string;
|
|
11
12
|
appcqid?: string;
|
|
12
13
|
srcqid?: string;
|
|
13
14
|
userinfo?: string;
|
|
@@ -31,6 +32,7 @@ interface IOpenLogParams {
|
|
|
31
32
|
xmlog: string;
|
|
32
33
|
isreturn?: 0 | 1 | 2 | 3;
|
|
33
34
|
querystring?: Record<string | number, any>;
|
|
35
|
+
manual?: boolean;
|
|
34
36
|
}
|
|
35
37
|
interface IActiveLogParams {
|
|
36
38
|
actentryid?: string;
|
|
@@ -66,15 +68,26 @@ interface IOnlineLogParams {
|
|
|
66
68
|
starttime: string;
|
|
67
69
|
}
|
|
68
70
|
declare type IOnlineLogParamsWithCommon = ICommonParams & IOnlineLogParams;
|
|
71
|
+
declare type IHwOnlineLogParamsWithCommon = IHwCommonParams & IOnlineLogParams;
|
|
69
72
|
interface IUserInfo {
|
|
70
73
|
[k: string | number]: any;
|
|
71
74
|
}
|
|
72
|
-
interface
|
|
73
|
-
language
|
|
75
|
+
interface ISystemInfo {
|
|
76
|
+
language?: string;
|
|
77
|
+
version: string;
|
|
78
|
+
SDKVersion?: string;
|
|
79
|
+
benchmarkLevel?: number;
|
|
80
|
+
theme?: string;
|
|
81
|
+
platform: string;
|
|
82
|
+
system: string;
|
|
83
|
+
model: string;
|
|
84
|
+
brand: string;
|
|
85
|
+
pixelRatio: number;
|
|
86
|
+
screenWidth: number;
|
|
87
|
+
screenHeight: number;
|
|
88
|
+
}
|
|
89
|
+
interface IExtraInfo extends Pick<ISystemInfo, 'language' | 'SDKVersion' | 'benchmarkLevel' | 'theme' | 'pixelRatio'> {
|
|
74
90
|
wxVersion: string;
|
|
75
|
-
SDKVersion: string;
|
|
76
|
-
benchmarkLevel: number;
|
|
77
|
-
theme: string;
|
|
78
91
|
}
|
|
79
92
|
interface IDomain {
|
|
80
93
|
open?: string;
|
|
@@ -135,6 +148,7 @@ interface IHwDomain {
|
|
|
135
148
|
open?: string;
|
|
136
149
|
act?: string;
|
|
137
150
|
ad?: string;
|
|
151
|
+
onlineUrl?: string;
|
|
138
152
|
}
|
|
139
153
|
interface HwInitParams {
|
|
140
154
|
isPro?: boolean;
|
|
@@ -169,6 +183,59 @@ interface IHwAdLogParams {
|
|
|
169
183
|
ecpm?: string;
|
|
170
184
|
adfrom?: string;
|
|
171
185
|
}
|
|
186
|
+
interface IRes<T = any> {
|
|
187
|
+
code: string;
|
|
188
|
+
msg: string;
|
|
189
|
+
data: T;
|
|
190
|
+
}
|
|
191
|
+
interface ICode2sessionParams {
|
|
192
|
+
apptypeid: string;
|
|
193
|
+
code: string;
|
|
194
|
+
testNet?: string | number;
|
|
195
|
+
}
|
|
196
|
+
interface ICode2sessionResponseData {
|
|
197
|
+
unionid?: string;
|
|
198
|
+
openid: string;
|
|
199
|
+
session_key: string;
|
|
200
|
+
}
|
|
201
|
+
interface IShareParams {
|
|
202
|
+
apptypeid: string;
|
|
203
|
+
openId: string;
|
|
204
|
+
}
|
|
205
|
+
interface ISubsidyParams extends IShareParams {
|
|
206
|
+
os: string;
|
|
207
|
+
}
|
|
208
|
+
interface ISubsidyResponseData {
|
|
209
|
+
hasSubsidy: boolean;
|
|
210
|
+
ksSubsidyLevelDetails: {
|
|
211
|
+
buyQuantity: string;
|
|
212
|
+
money: number;
|
|
213
|
+
subsidyMoney: number;
|
|
214
|
+
subsidyAfterMoney: number;
|
|
215
|
+
}[];
|
|
216
|
+
}
|
|
217
|
+
declare type IUserPropsParams = IShareParams;
|
|
218
|
+
interface IUserPropsResponseData {
|
|
219
|
+
[k: string]: string | number;
|
|
220
|
+
}
|
|
221
|
+
interface ICheckOrderParams extends IShareParams {
|
|
222
|
+
orderId: string;
|
|
223
|
+
}
|
|
224
|
+
interface ICheckOrderResponseData {
|
|
225
|
+
payResult: string | number;
|
|
226
|
+
}
|
|
227
|
+
interface ICreateOrderParams extends IShareParams {
|
|
228
|
+
productId?: string;
|
|
229
|
+
payPlatform?: string;
|
|
230
|
+
}
|
|
231
|
+
interface ICreateOrderResponseData {
|
|
232
|
+
payContent: any;
|
|
233
|
+
amount: string;
|
|
234
|
+
amountCents: string;
|
|
235
|
+
orderId: string;
|
|
236
|
+
productId: string;
|
|
237
|
+
productName: string;
|
|
238
|
+
}
|
|
172
239
|
|
|
173
240
|
declare class XLog {
|
|
174
241
|
version: string;
|
|
@@ -176,6 +243,8 @@ declare class XLog {
|
|
|
176
243
|
private _openUrl;
|
|
177
244
|
private _actUrl;
|
|
178
245
|
private _adUrl;
|
|
246
|
+
private _onlineUrl;
|
|
247
|
+
private _startTime;
|
|
179
248
|
private _commonParams;
|
|
180
249
|
get commonParams(): IHwCommonParams;
|
|
181
250
|
private _isPro;
|
|
@@ -214,6 +283,11 @@ declare class XLog {
|
|
|
214
283
|
act(params: IHwActiveLogParams): void;
|
|
215
284
|
/** 上报广告日志 */
|
|
216
285
|
ad(params: IHwAdLogParams): void;
|
|
286
|
+
private _sendOnline;
|
|
287
|
+
private _setOnlineBatchData;
|
|
288
|
+
private _getOnlineBatchData;
|
|
289
|
+
private _clearOnlineBatchData;
|
|
290
|
+
private _online;
|
|
217
291
|
}
|
|
218
292
|
|
|
219
|
-
export { EGender, HwInitParams, IActiveLogParams, IAdLogParams, ICommonParams, IDomain, IDomainWithEnv, IEventLogParams, IExtraInfo, IHwActiveLogParams, IHwAdLogParams, IHwCommonParams, IHwDomain, IHwOpenLogParams, IOnlineLogParams, IOnlineLogParamsWithCommon, IOpenLogParams, IUserInfo, InitParams, MiniprogramShowOptions, TCommonParams, THwCommonParams, TPlatform, XLog };
|
|
293
|
+
export { EGender, HwInitParams, IActiveLogParams, IAdLogParams, ICheckOrderParams, ICheckOrderResponseData, ICode2sessionParams, ICode2sessionResponseData, ICommonParams, ICreateOrderParams, ICreateOrderResponseData, IDomain, IDomainWithEnv, IEventLogParams, IExtraInfo, IHwActiveLogParams, IHwAdLogParams, IHwCommonParams, IHwDomain, IHwOnlineLogParamsWithCommon, IHwOpenLogParams, IOnlineLogParams, IOnlineLogParamsWithCommon, IOpenLogParams, IRes, IShareParams, ISubsidyParams, ISubsidyResponseData, ISystemInfo, IUserInfo, IUserPropsParams, IUserPropsResponseData, InitParams, MiniprogramShowOptions, TCommonParams, THwCommonParams, TPlatform, XLog };
|