Skip to content
本页导读

企业微信SDK

暂时仅支持Android

平台兼容性

AndroidiOSweb鸿蒙 Next小程序
xxx

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxxx

Api

事件名参数说明
registerRegisterOptions注册
isInstalled-是否安装微信
openApp-打开微信
loginLoginOptions登录
shareShareOptions分享

示例代码

ts
<script setup>
	// #ifdef APP-ANDROID
	import * as wxwork from "@/uni_modules/ux-wxwork"
	import { UxLoginOptions, UxRegisterOptions, UxShareOptions, UxMiniProgram } from "@/uni_modules/ux-wxwork"
	// #endif
	
	let title = ''
	
	const code = ref('')
	
	function isAPP(): boolean {
		// #ifdef APP
		return true
		// #endif
		// #ifndef APP
		uni.showToast({
			title: '仅支持APP',
			icon: 'none'
		})
		return false
		// #endif
	}
	
	function isInstalled() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		uni.showToast({
			title: wxwork.isInstalled() ? '已安装企业微信' : '未安装企业微信',
			icon: 'none'
		})
		// #endif
	}
	
	function onAuth() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.login({
			success: (res) => {
				console.log(res);
				code.value = res.code
				uni.showModal({
					title: '登录成功',
					content: `登录凭证:${res.code}`
				})
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxLoginOptions)
		// #endif
	}
	
	function shareWebpage() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 0,
			title: 'UxFrame低代码高性能UI框架',
			summary: 'UxFrame是基于UNI-APP-X开发的低代码高性能原生UI框架',
			href: 'https://www.uxframe.cn',
			// imageUrl: '/static/logo.png',
			imageUrl: 'https://www.uxframe.cn/logo/logo.png',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareText() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 1,
			title: 'UxFrame低代码高性能UI框架',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareImage() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 2,
			// imageUrl: '/static/logo.png'
			imageUrl: 'https://www.uxframe.cn/logo/logo.png',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareFile() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 3,
			title: 'UxFrame低代码高性能UI框架',
			summary: 'UxFrame是基于UNI-APP-X开发的低代码高性能原生UI框架',
			filePath: 'http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareVideo() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 4,
			title: 'UxFrame低代码高性能UI框架',
			summary: 'UxFrame是基于UNI-APP-X开发的低代码高性能原生UI框架',
			// imageUrl: '/static/logo.png'
			imageUrl: 'https://www.uxframe.cn/logo/logo.png',
			mediaUrl: 'https://www.uxframe.cn/source/intro/demo.mp4',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareMp() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 5,
			title: 'UxFrame低代码高性能UI框架',
			summary: 'UxFrame是基于UNI-APP-X开发的低代码高性能原生UI框架',
			// imageUrl: '/static/logo.png'
			imageUrl: 'https://www.uxframe.cn/logo/logo.png',
			miniProgram: {
				id: 'gh_b54c53753cee',
				type: 0,
				path: '',
				webUrl: 'https://www.uxframe.cn'
			} as UxMiniProgram,
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function openApp() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.openApp()
		// #endif
	}
	
	onLoad((e: OnLoadOptions) => {
		title = e['title'] ?? ''
		
		// #ifdef APP-ANDROID
		wxwork.register({
			appid: 'ww0440c17d26e52347',
			agentid: '1000004',
			schema: 'wwauth0440c17d26e52347000004',
			success: (res) => {
				console.log(res)
			}
		} as UxRegisterOptions)
		// #endif
	})
	
</script>
<script setup>
	// #ifdef APP-ANDROID
	import * as wxwork from "@/uni_modules/ux-wxwork"
	import { UxLoginOptions, UxRegisterOptions, UxShareOptions, UxMiniProgram } from "@/uni_modules/ux-wxwork"
	// #endif
	
	let title = ''
	
	const code = ref('')
	
	function isAPP(): boolean {
		// #ifdef APP
		return true
		// #endif
		// #ifndef APP
		uni.showToast({
			title: '仅支持APP',
			icon: 'none'
		})
		return false
		// #endif
	}
	
	function isInstalled() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		uni.showToast({
			title: wxwork.isInstalled() ? '已安装企业微信' : '未安装企业微信',
			icon: 'none'
		})
		// #endif
	}
	
	function onAuth() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.login({
			success: (res) => {
				console.log(res);
				code.value = res.code
				uni.showModal({
					title: '登录成功',
					content: `登录凭证:${res.code}`
				})
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxLoginOptions)
		// #endif
	}
	
	function shareWebpage() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 0,
			title: 'UxFrame低代码高性能UI框架',
			summary: 'UxFrame是基于UNI-APP-X开发的低代码高性能原生UI框架',
			href: 'https://www.uxframe.cn',
			// imageUrl: '/static/logo.png',
			imageUrl: 'https://www.uxframe.cn/logo/logo.png',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareText() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 1,
			title: 'UxFrame低代码高性能UI框架',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareImage() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 2,
			// imageUrl: '/static/logo.png'
			imageUrl: 'https://www.uxframe.cn/logo/logo.png',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareFile() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 3,
			title: 'UxFrame低代码高性能UI框架',
			summary: 'UxFrame是基于UNI-APP-X开发的低代码高性能原生UI框架',
			filePath: 'http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareVideo() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 4,
			title: 'UxFrame低代码高性能UI框架',
			summary: 'UxFrame是基于UNI-APP-X开发的低代码高性能原生UI框架',
			// imageUrl: '/static/logo.png'
			imageUrl: 'https://www.uxframe.cn/logo/logo.png',
			mediaUrl: 'https://www.uxframe.cn/source/intro/demo.mp4',
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function shareMp() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.share({
			type: 5,
			title: 'UxFrame低代码高性能UI框架',
			summary: 'UxFrame是基于UNI-APP-X开发的低代码高性能原生UI框架',
			// imageUrl: '/static/logo.png'
			imageUrl: 'https://www.uxframe.cn/logo/logo.png',
			miniProgram: {
				id: 'gh_b54c53753cee',
				type: 0,
				path: '',
				webUrl: 'https://www.uxframe.cn'
			} as UxMiniProgram,
			success: (res) => {
				console.log(res);
			},
			fail: (err) => {
				console.log(err);
			}
		} as UxShareOptions)
		// #endif
	}
	
	function openApp() {
		if(!isAPP()) return
		
		// #ifdef APP-ANDROID
		wxwork.openApp()
		// #endif
	}
	
	onLoad((e: OnLoadOptions) => {
		title = e['title'] ?? ''
		
		// #ifdef APP-ANDROID
		wxwork.register({
			appid: 'ww0440c17d26e52347',
			agentid: '1000004',
			schema: 'wwauth0440c17d26e52347000004',
			success: (res) => {
				console.log(res)
			}
		} as UxRegisterOptions)
		// #endif
	})
	
</script>
html
<template>
	<ux-page>
		<ux-navbar :title="title" :border="false"></ux-navbar>
		
		<ux-scroll>
			<ux-card direction="column" icon="flag-filled" title="企业微信SDK" :bold="true">
				<ux-text text="支持企业微信授权、分享等功能"></ux-text>
				<ux-row :flex="true" align="top" :mt="5" style="width: 100%;">
					<ux-text text="详细文档:"></ux-text>
					<ux-text style="flex: 1" name="企业微信SDK" text="https://www.uxframe.cn/api/weixin.html" path="/pages/webview/webview" mode="link"</ux-text>
				</ux-row>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="基本" :bold="true">
				<ux-col>
					<ux-button text="是否安装企业微信" @click="isInstalled()"></ux-button>
					<ux-button text="打开企业微信" :mt="10" @click="openApp()"></ux-button>
				</ux-col>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="企业微信授权" :bold="true">
				<ux-col>
					<ux-text :text="code"></ux-text>
					
					<ux-button text="拉起授权" :mt="10" @click="onAuth()"></ux-button>
				</ux-col>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="企业微信分享" :bold="true">
				<ux-col>
					<ux-button text="图文" @click="shareWebpage()"></ux-button>
					<ux-button text="文本" :mt="10" @click="shareText()"></ux-button>
					<ux-button text="图片" :mt="10" @click="shareImage()"></ux-button>
					<ux-button text="文件" :mt="10" @click="shareFile()"></ux-button>
					<ux-button text="视频" :mt="10" @click="shareVideo()"></ux-button>
					<ux-button text="小程序" :mt="10" @click="shareMp()"></ux-button>
				</ux-col>
			</ux-card>
			
			<ux-placeholder :height="200">
				<ux-row justify="center" align="center" style="height: 100%;">
					<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
				</ux-row>
			</ux-placeholder>
		</ux-scroll>
		
	</ux-page>
</template>
<template>
	<ux-page>
		<ux-navbar :title="title" :border="false"></ux-navbar>
		
		<ux-scroll>
			<ux-card direction="column" icon="flag-filled" title="企业微信SDK" :bold="true">
				<ux-text text="支持企业微信授权、分享等功能"></ux-text>
				<ux-row :flex="true" align="top" :mt="5" style="width: 100%;">
					<ux-text text="详细文档:"></ux-text>
					<ux-text style="flex: 1" name="企业微信SDK" text="https://www.uxframe.cn/api/weixin.html" path="/pages/webview/webview" mode="link"</ux-text>
				</ux-row>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="基本" :bold="true">
				<ux-col>
					<ux-button text="是否安装企业微信" @click="isInstalled()"></ux-button>
					<ux-button text="打开企业微信" :mt="10" @click="openApp()"></ux-button>
				</ux-col>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="企业微信授权" :bold="true">
				<ux-col>
					<ux-text :text="code"></ux-text>
					
					<ux-button text="拉起授权" :mt="10" @click="onAuth()"></ux-button>
				</ux-col>
			</ux-card>
			
			<ux-card direction="column" icon="arrowright" title="企业微信分享" :bold="true">
				<ux-col>
					<ux-button text="图文" @click="shareWebpage()"></ux-button>
					<ux-button text="文本" :mt="10" @click="shareText()"></ux-button>
					<ux-button text="图片" :mt="10" @click="shareImage()"></ux-button>
					<ux-button text="文件" :mt="10" @click="shareFile()"></ux-button>
					<ux-button text="视频" :mt="10" @click="shareVideo()"></ux-button>
					<ux-button text="小程序" :mt="10" @click="shareMp()"></ux-button>
				</ux-col>
			</ux-card>
			
			<ux-placeholder :height="200">
				<ux-row justify="center" align="center" style="height: 100%;">
					<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
				</ux-row>
			</ux-placeholder>
		</ux-scroll>
		
	</ux-page>
</template>
css
<style lang="scss">
	
</style>
<style lang="scss">
	
</style>