@@ -51,6 +51,7 @@ | |||||
"@dcloudio/uni-mp-toutiao": "3.0.0-3070920230324001", | "@dcloudio/uni-mp-toutiao": "3.0.0-3070920230324001", | ||||
"@dcloudio/uni-mp-weixin": "3.0.0-3070920230324001", | "@dcloudio/uni-mp-weixin": "3.0.0-3070920230324001", | ||||
"@dcloudio/uni-quickapp-webview": "3.0.0-3070920230324001", | "@dcloudio/uni-quickapp-webview": "3.0.0-3070920230324001", | ||||
"@szyx/szyx-push-web": "^0.0.1", | |||||
"axios": "^1.3.4", | "axios": "^1.3.4", | ||||
"fingerprintjs2": "^2.1.4", | "fingerprintjs2": "^2.1.4", | ||||
"net": "^1.0.2", | "net": "^1.0.2", | ||||
@@ -1,7 +1,19 @@ | |||||
<script> | <script> | ||||
import SzyxPush, {MsgType} from "@szyx/szyx-push-web"; | |||||
export default { | export default { | ||||
onLaunch: function () { | onLaunch: function () { | ||||
console.log('App Launch') | console.log('App Launch') | ||||
this.$SzyxPush.register('xuqm').then(() => { | |||||
console.log('>>>>>', 'IM连接成功') | |||||
}).catch(error => { | |||||
console.log('>>>>>', 'im连接失败', error) | |||||
}) | |||||
SzyxPush.onMessage((type, msg) => { | |||||
console.log('新消息送达', msg) | |||||
if (type === MsgType.text) | |||||
this.msg = msg.message.text | |||||
}) | |||||
}, | }, | ||||
onShow: function () { | onShow: function () { | ||||
console.log('App Show') | console.log('App Show') | ||||
@@ -1,23 +1,25 @@ | |||||
import {createSSRApp} from "vue"; | import {createSSRApp} from "vue"; | ||||
import App from "./App.vue"; | import App from "./App.vue"; | ||||
import SzyxPush from "@szyx/szyx-push-web"; | |||||
import SzyxPush from "./szyx-push-sdk"; | |||||
SzyxPush.init('sdada', 'wx').then(() => { | |||||
console.log('IM初始化完成') | |||||
}) | |||||
SzyxPush.register('xuqm').then(r => { | |||||
console.log('注册im服务完成') | |||||
}).catch(e => { | |||||
console.log('注册im服务失败', e) | |||||
}) | |||||
SzyxPush.onMessage((type, msg) => { | |||||
console.log('收到消息', type, msg) | |||||
}) | |||||
// import SzyxPush from "./szyx-push-sdk"; | |||||
// | |||||
// | |||||
// SzyxPush.init('sdada', 'wx').then(() => { | |||||
// console.log('IM初始化完成') | |||||
// }) | |||||
// SzyxPush.register('xuqm').then(r => { | |||||
// console.log('注册im服务完成') | |||||
// }).catch(e => { | |||||
// console.log('注册im服务失败', e) | |||||
// }) | |||||
// SzyxPush.onMessage((type, msg) => { | |||||
// console.log('收到消息', type, msg) | |||||
// }) | |||||
export function createApp() { | export function createApp() { | ||||
const app = createSSRApp(App); | const app = createSSRApp(App); | ||||
app.use(SzyxPush, '123456', OsType.wx) | |||||
return { | return { | ||||
app, | app, | ||||
}; | }; | ||||
@@ -0,0 +1,89 @@ | |||||
declare const SzyxPush: ISzyxPush; | |||||
export default SzyxPush; | |||||
export const enum OsType { | |||||
ios = 1, | |||||
android = 2, | |||||
web = 3, | |||||
windows = 4, | |||||
mac = 5, | |||||
wx = 6, | |||||
unknown = -1, | |||||
} | |||||
export const enum MsgType { | |||||
unknown = -1, | |||||
text = 1, | |||||
voice = 2, | |||||
image = 3, | |||||
location = 4, | |||||
video = 5, | |||||
file = 6, | |||||
at = 7, | |||||
other = 8, | |||||
log = 9, | |||||
} | |||||
export declare type MessageListener = (messageType: MsgType, message: Message) => void; | |||||
/** | |||||
* 当messageType为text的时候,返回这个 | |||||
*/ | |||||
export declare interface TextMessage { | |||||
text: string | |||||
} | |||||
export declare interface PictureMessage { | |||||
url: string | |||||
thumbnail: string | |||||
thumbnailWidth: number | |||||
thumbnailHeight: number | |||||
} | |||||
export declare interface Message { | |||||
/** | |||||
* 租户id | |||||
*/ | |||||
tenantNo: string; | |||||
messageType: MsgType; | |||||
messageId: string; | |||||
target: string; | |||||
fromClientId: string; | |||||
toClientId: string; | |||||
timestamp: number; | |||||
message: string | TextMessage | PictureMessage; | |||||
} | |||||
export declare interface ISzyxPush { | |||||
install(app, tenantNo: string, osType: OsType): Promise<void>; | |||||
/** | |||||
* 初始化方法,建议放在main.js中 | |||||
* @param tenantNo 租户id,在平台获取 | |||||
* @param osType 设备类型 | |||||
*/ | |||||
init(tenantNo: string, osType: OsType): Promise<void>; | |||||
register(userId: string): Promise<void>; | |||||
/** | |||||
*添加消息回调,到达的消息统一分发入口 | |||||
* @param callback | |||||
* @return callbackId 页面关闭时记得用 {@link unMessage}注销 | |||||
*/ | |||||
onMessage(callback: MessageListener): number; | |||||
/** | |||||
*注销消息回调 | |||||
* @param callId 由{@link onMessage}返回 | |||||
*/ | |||||
unMessage(callId): void; | |||||
sendTextMsg(userId: string, text: string): Promise<Message>; | |||||
} |
@@ -18,6 +18,9 @@ class SzyxPushClient { | |||||
this._client = null; | this._client = null; | ||||
this.socketOpen = false; | this.socketOpen = false; | ||||
this.ws = { | |||||
send: this.sendSocketMessage | |||||
} | |||||
} | } | ||||
guid() { | guid() { | ||||
@@ -105,9 +108,6 @@ class SzyxPushClient { | |||||
}) | }) | ||||
} | } | ||||
ws = { | |||||
send: this.sendSocketMessage | |||||
} | |||||
_connectClient(resolve, reject) { | _connectClient(resolve, reject) { | ||||