插件地址:前往地址
兼容端
| 安卓 | 苹果 | Web | 鸿蒙 | 小程序 |
|---|---|---|---|---|
| ✅ | ✅ | ❌ | ❌ | ❌ |
配置文档
- 在根目录创建
AndroidManifest.xml,放入以下代码
xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="你的包名">
<application>
<meta-data android:name="com.alipay.app.id" android:value="你的应用Appid" />
<meta-data android:name="com.alipay.public.key" android:value="" />
<activity android:exported="true" android:name="com.alipay.sdk.app.AlipayResultActivity" tools:node="merge">
<intent-filter tools:node="replace">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- 用于跳回App -->
<data android:scheme="你的应用scheme" />
</intent-filter>
</activity>
</application>
</manifest>uni-app x 示例代码
vue
<script setup lang="uts">
import { tAlipayOpenAuthScheme,TAlipayApiOptions,TAlipayApiResult } from "@/uni_modules/t-alipay-api";
const login = () => {
new Promise((resolve,reject) => {
tAlipayOpenAuthScheme({
url: `https://authweb.alipay.com/auth?auth_type=PURE_OAUTH_SDK&app_id=你的APPID&scope=auth_user&state=init`,
scheme: "你的scheme", // ios必填
resolve,
reject
} as TAlipayApiOptions)
}).then((result: TAlipayApiResult) =>{
console.log(result)
}).catch((error: TAlipayApiResult)=>{
console.log(error)
})
}
</script>uni-app vue3 示例代码
vue
<script setup>
import { tAlipayOpenAuthScheme } from "@/uni_modules/t-alipay-api";
const login = () => {
new Promise((resolve,reject) => {
tAlipayOpenAuthScheme({
url: `https://authweb.alipay.com/auth?auth_type=PURE_OAUTH_SDK&app_id=你的APPID&scope=auth_user&state=init`,
scheme: "你的scheme", // ios必填
resolve,
reject
})
}).then((result) =>{
console.log(result)
}).catch((error)=>{
console.log(error)
})
}
</script>uni-app vue2 示例代码
vue
<script>
import { tAlipayOpenAuthScheme } from "@/uni_modules/t-alipay-api";
export default {
methods: {
login() {
new Promise((resolve,reject) => {
tAlipayOpenAuthScheme({
url: `https://authweb.alipay.com/auth?auth_type=PURE_OAUTH_SDK&app_id=你的APPID&scope=auth_user&state=init`,
scheme: "你的scheme", // ios必填
resolve,
reject
})
}).then((result) =>{
console.log(result)
}).catch((error)=>{
console.log(error)
})
}
}
}
</script>暴露的类型
ts
export type TAlipayData = {
authCode: string;
}
export type TAlipayApiResult = {
code: number;
msg: string;
data?: TAlipayData;
}
export type TAlipayApiOptions = {
url: string;
scheme: string;
resolve?: (result:TAlipayApiResult) => void;
reject?: (result:TAlipayApiResult) => void;
}
// #ifdef APP-IOS
export type TAlipayOpenAuthSchemeApi = (options: TAlipayApiOptions) => void;
// #endif
