feat: 支付宝登录测试&

This commit is contained in:
2025-10-18 17:31:15 +08:00
parent b8006c8498
commit 7214c8dc6f
16 changed files with 1124 additions and 918 deletions
+14
View File
@@ -139,6 +139,20 @@
"pid" : "11931", "pid" : "11931",
"parameters" : {} "parameters" : {}
} }
},
"WITTestUniPlugin" : {
"__plugin_info__" : {
"name" : "WITTestUniPlugin",
"description" : "iOS原生插件",
"platforms" : "iOS",
"url" : "",
"android_package_name" : "",
"ios_bundle_id" : "",
"isCloud" : false,
"bought" : -1,
"pid" : "",
"parameters" : {}
}
} }
} }
}, },
@@ -0,0 +1,16 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
FOUNDATION_EXPORT double WITTestUniPluginVersionNumber;
FOUNDATION_EXPORT const unsigned char WITTestUniPluginVersionString[];
@@ -0,0 +1,6 @@
framework module WITTestUniPlugin {
umbrella header "WITTestUniPlugin-umbrella.h"
export *
module * { export * }
}
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict>
<key>Headers/WITTestUniPlugin-umbrella.h</key>
<data>
sy6fvvVyh3Hq55ggZ631/oeqa4I=
</data>
<key>Info.plist</key>
<data>
FPcXGdMbWGdTQijRlJ+7nR/KGYg=
</data>
<key>Modules/module.modulemap</key>
<data>
ZjoU2LSV3I6Ja00k/RA4RMc2K+U=
</data>
</dict>
<key>files2</key>
<dict>
<key>Headers/WITTestUniPlugin-umbrella.h</key>
<dict>
<key>hash</key>
<data>
sy6fvvVyh3Hq55ggZ631/oeqa4I=
</data>
<key>hash2</key>
<data>
S+/WwO1UzL/8TSMb+wfLG/fLqvGlyFIbd0PV6EKkTPY=
</data>
</dict>
<key>Modules/module.modulemap</key>
<dict>
<key>hash</key>
<data>
ZjoU2LSV3I6Ja00k/RA4RMc2K+U=
</data>
<key>hash2</key>
<data>
o6k+82QmVbWgccrZRooVbNITdXrkdiGH1Jg6mz8v28k=
</data>
</dict>
</dict>
<key>rules</key>
<dict>
<key>^.*</key>
<true/>
<key>^.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^.*</key>
<true/>
<key>^.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>
@@ -0,0 +1,24 @@
{
"name":"WITTestUniPlugin",
"id":"WITTestUniPlugin",
"version":"0.1.0",
"description":"iOS原生插件",
"_dp_type":"nativeplugin",
"_dp_nativeplugin":{
"ios":{
"plugins":[
{
"type":"module",
"name":"WITTestUniPlugin",
"class":"WITTestUniModule"
}
],
"integrateType":"framework",
"deploymentTarget":"10.0",
"frameworks":[
"Foundation.framework",
"UIKit.framework"
]
}
}
}
+17 -3
View File
@@ -103,8 +103,9 @@
bgColor="#f1f6ff00" bgColor="#f1f6ff00"
></up-image> ></up-image>
微信登录 微信登录
</view> </view>
<view v-if="!isIOS" class="login_other_item" @click="alipayOneLogin"> <view class="login_other_item" @click="aa">
<!-- <view v-if="!isIOS" class="login_other_item" @click="alipayOneLogin"> -->
<up-image <up-image
src="/static/login/ZFB.png" src="/static/login/ZFB.png"
width="44" width="44"
@@ -202,7 +203,20 @@ export default {
loading: false, loading: false,
}; };
}, },
methods: { methods: {
aa(){
const nativiPlugin = uni.requireNativePlugin('WITTestUniPlugin');
console.log("隐藏原生tabbar",nativiPlugin)
nativiPlugin.testAsyncFunc({},
(ret) => {
uni.showToast({
title: '调用异步方法 ' + ret,
icon: "none"
})
console.log(ret);
});
},
jumpHome() { jumpHome() {
// const sysPlatform = getCurrentSysPlatform(); // const sysPlatform = getCurrentSysPlatform();
// if(sysPlatform === "android"){ // if(sysPlatform === "android"){
@@ -23,19 +23,19 @@
### 示例: ### 示例:
```javascript ```javascript
uni.requestMerchantTransfer({ uni.requestMerchantTransfer({
"mchId": "mchId", "mchId": "mchId",
"appId": "微信开发者平台对应app的APPID", "appId": "微信开发者平台对应app的APPID",
"package": "package", "package": "package",
success: (res) => { success: (res) => {
console.log(res) console.log(res)
}, },
fail: (res) => { fail: (res) => {
console.log(res.errMsg) console.log(res.errMsg)
}, },
complete: (res) => { complete: (res) => {
console.log(res.errMsg) console.log(res.errMsg)
} }
}) })
``` ```
@@ -48,32 +48,32 @@ iOS平台必须在项目根目录下的 [Info.plist](https://uniapp.dcloud.net.c
示例如下: 示例如下:
```xml ```xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>WeChat</key> <key>WeChat</key>
<dict> <dict>
<key>appid</key> <key>appid</key>
<string>请填写微信开发者平台对应app的APPID</string> <string>请填写微信开发者平台对应app的APPID</string>
<key>universalLink</key> <key>universalLink</key>
<string>请填写能唤起当前应用的Universal Links路径</string> <string>请填写能唤起当前应用的Universal Links路径</string>
</dict> </dict>
<key>CFBundleURLTypes</key> <key>CFBundleURLTypes</key>
<array> <array>
<dict> <dict>
<key>CFBundleTypeRole</key> <key>CFBundleTypeRole</key>
<string>Editor</string> <string>Editor</string>
<key>CFBundleURLName</key> <key>CFBundleURLName</key>
<string>WeChat</string> <string>WeChat</string>
<key>CFBundleURLSchemes</key> <key>CFBundleURLSchemes</key>
<array> <array>
<string>请填写微信开发者平台对应app的APPID</string> <string>请填写微信开发者平台对应app的APPID</string>
</array> </array>
</dict> </dict>
</array> </array>
</dict> </dict>
</plist> </plist>
``` ```
@@ -1,11 +1,11 @@
{ {
"frameworks": [ "frameworks": [
"CoreGraphics.framework", "CoreGraphics.framework",
"WebKit.framework", "WebKit.framework",
"Security.framework" "Security.framework"
], ],
"deploymentTarget": "12", "deploymentTarget": "12",
"plists": { "plists": {
"LSApplicationQueriesSchemes": ["weixin", "weixinULAPI", "weixinURLParamsAPI"] "LSApplicationQueriesSchemes": ["weixin", "weixinULAPI", "weixinURLParamsAPI"]
} }
} }
@@ -1,158 +1,158 @@
import { UIApplication } from "UIKit"; import { UIApplication } from "UIKit";
import { URL, NSUserActivity, Bundle, URLComponents, URLQueryItem, Script } from "Foundation"; import { URL, NSUserActivity, Bundle, URLComponents, URLQueryItem, Script } from "Foundation";
import { RequestMerchantTransfer, RequestMerchantTransferOptions, RequestMerchantTransferGeneralCallbackResult } from '../interface.uts'; import { RequestMerchantTransfer, RequestMerchantTransferOptions, RequestMerchantTransferGeneralCallbackResult } from '../interface.uts';
export const requestMerchantTransfer : RequestMerchantTransfer = function (options : RequestMerchantTransferOptions) { export const requestMerchantTransfer : RequestMerchantTransfer = function (options : RequestMerchantTransferOptions) {
WxpayManager.requestMerchantTransfer(options) WxpayManager.requestMerchantTransfer(options)
} }
export class WxpayManagerHookProxy implements UTSiOSHookProxy { export class WxpayManagerHookProxy implements UTSiOSHookProxy {
// 应用正常启动时 (不包括已在后台转到前台的情况)的回调函数。 // 应用正常启动时 (不包括已在后台转到前台的情况)的回调函数。
applicationDidFinishLaunchingWithOptions(application : UIApplication | null, launchOptions : Map<UIApplication.LaunchOptionsKey, any> | null = null) : boolean { applicationDidFinishLaunchingWithOptions(application : UIApplication | null, launchOptions : Map<UIApplication.LaunchOptionsKey, any> | null = null) : boolean {
WxpayManager.registerApp() WxpayManager.registerApp()
return false return false
} }
// 通过 url scheme 方式唤起 app 时的回调函数。 // 通过 url scheme 方式唤起 app 时的回调函数。
applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map<UIApplication.OpenURLOptionsKey, any> | null = null) : boolean { applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map<UIApplication.OpenURLOptionsKey, any> | null = null) : boolean {
WxpayManager.handleOpen(url) WxpayManager.handleOpen(url)
return true return true
} }
// 当应用程序接收到与用户活动相关的数据时调用此方法,例如,当用户使用 Universal Link 唤起应用时。 // 当应用程序接收到与用户活动相关的数据时调用此方法,例如,当用户使用 Universal Link 唤起应用时。
applicationContinueUserActivityRestorationHandler(application : UIApplication | null, userActivity : NSUserActivity | null, restorationHandler : ((res : [any] | null) => void) | null = null) : boolean { applicationContinueUserActivityRestorationHandler(application : UIApplication | null, userActivity : NSUserActivity | null, restorationHandler : ((res : [any] | null) => void) | null = null) : boolean {
WxpayManager.handleOpenUniversalLink(userActivity) WxpayManager.handleOpenUniversalLink(userActivity)
return true return true
} }
} }
class WxpayManager implements WXApiDelegate { class WxpayManager implements WXApiDelegate {
private static shared = new WxpayManager() private static shared = new WxpayManager()
private static options ?: RequestMerchantTransferOptions private static options ?: RequestMerchantTransferOptions
@UTSiOS.keyword("fileprivate") @UTSiOS.keyword("fileprivate")
static registerApp() { static registerApp() {
const scheme = WxpayManager.getApplicationScheme() const scheme = WxpayManager.getApplicationScheme()
const universalLink = WxpayManager.getApplicationUniversalLink() const universalLink = WxpayManager.getApplicationUniversalLink()
if (scheme != null && scheme != "" && universalLink != null && universalLink != "") { if (scheme != null && scheme != "" && universalLink != null && universalLink != "") {
WXApi.registerApp(scheme!, universalLink = universalLink!) WXApi.registerApp(scheme!, universalLink = universalLink!)
} }
} }
@UTSiOS.keyword("fileprivate") @UTSiOS.keyword("fileprivate")
static handleOpen(url : URL) { static handleOpen(url : URL) {
WXApi.handleOpen(url, delegate = shared) WXApi.handleOpen(url, delegate = shared)
} }
@UTSiOS.keyword("fileprivate") @UTSiOS.keyword("fileprivate")
static handleOpenUniversalLink(userActivity : NSUserActivity | null) { static handleOpenUniversalLink(userActivity : NSUserActivity | null) {
if (userActivity != null) { if (userActivity != null) {
WXApi.handleOpenUniversalLink(userActivity!, delegate = shared) WXApi.handleOpenUniversalLink(userActivity!, delegate = shared)
} }
} }
private static getApplicationScheme() : string | null { private static getApplicationScheme() : string | null {
let scheme : string | null = null let scheme : string | null = null
const infoDictionary = Bundle.main.infoDictionary const infoDictionary = Bundle.main.infoDictionary
if (infoDictionary != null) { if (infoDictionary != null) {
const wechat = infoDictionary!['WeChat'] as Map<string, any> | null const wechat = infoDictionary!['WeChat'] as Map<string, any> | null
if (wechat != null) { if (wechat != null) {
scheme = wechat!['appid'] as string | null scheme = wechat!['appid'] as string | null
} }
} }
return scheme return scheme
} }
private static getApplicationUniversalLink() : string | null { private static getApplicationUniversalLink() : string | null {
let universalLink : string | null = null let universalLink : string | null = null
const infoDictionary = Bundle.main.infoDictionary const infoDictionary = Bundle.main.infoDictionary
if (infoDictionary != null) { if (infoDictionary != null) {
const wechat = infoDictionary!['WeChat'] as Map<string, any> | null const wechat = infoDictionary!['WeChat'] as Map<string, any> | null
if (wechat != null) { if (wechat != null) {
universalLink = wechat!['universalLink'] as string | null universalLink = wechat!['universalLink'] as string | null
} }
} }
return universalLink return universalLink
} }
//@brief 检查微信是否已被用户安装 //@brief 检查微信是否已被用户安装
@UTSiOS.keyword("fileprivate") @UTSiOS.keyword("fileprivate")
static isWXAppInstalled() : boolean { static isWXAppInstalled() : boolean {
const url = URL(string = "weixin://")! const url = URL(string = "weixin://")!
if (UIApplication.shared.canOpenURL(url)) { if (UIApplication.shared.canOpenURL(url)) {
return true return true
} }
return false return false
} }
static buildQueryString(parameters : Map<string, string>) : string | null { static buildQueryString(parameters : Map<string, string>) : string | null {
let components = URLComponents() let components = URLComponents()
let queryItems : [URLQueryItem] = [] let queryItems : [URLQueryItem] = []
parameters.forEach((value, key) => { parameters.forEach((value, key) => {
queryItems.append(URLQueryItem(name = key, value = value)) queryItems.append(URLQueryItem(name = key, value = value))
}) })
components.queryItems = queryItems components.queryItems = queryItems
return components.percentEncodedQuery return components.percentEncodedQuery
} }
static requestMerchantTransfer(options : RequestMerchantTransferOptions) { static requestMerchantTransfer(options : RequestMerchantTransferOptions) {
WxpayManager.options = options WxpayManager.options = options
if (WxpayManager.isWXAppInstalled() == false) { if (WxpayManager.isWXAppInstalled() == false) {
var res : RequestMerchantTransferGeneralCallbackResult = { var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '微信没有安装' errMsg: '微信没有安装'
} }
options.fail?.(res) options.fail?.(res)
options.complete?.(res) options.complete?.(res)
} }
if (WxpayManager.getApplicationScheme() == null || WxpayManager.getApplicationScheme() == "") { if (WxpayManager.getApplicationScheme() == null || WxpayManager.getApplicationScheme() == "") {
var res : RequestMerchantTransferGeneralCallbackResult = { var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '没有配置对应的URL Scheme' errMsg: '没有配置对应的URL Scheme'
} }
options.fail?.(res) options.fail?.(res)
options.complete?.(res) options.complete?.(res)
return return
} }
if (WxpayManager.getApplicationUniversalLink() == null || WxpayManager.getApplicationUniversalLink() == "") { if (WxpayManager.getApplicationUniversalLink() == null || WxpayManager.getApplicationUniversalLink() == "") {
var res : RequestMerchantTransferGeneralCallbackResult = { var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '没有配置对应的Universal Link' errMsg: '没有配置对应的Universal Link'
} }
options.fail?.(res) options.fail?.(res)
options.complete?.(res) options.complete?.(res)
return return
} }
if (WxpayManager.options != null) { if (WxpayManager.options != null) {
const parameters = new Map<string, string>() const parameters = new Map<string, string>()
parameters.set('mchId', options.mchId) parameters.set('mchId', options.mchId)
parameters.set('package', options.package) parameters.set('package', options.package)
if (options.appId != null) { if (options.appId != null) {
parameters.set('appId', options.appId!) parameters.set('appId', options.appId!)
} }
if (options.openId != null) { if (options.openId != null) {
parameters.set('openId', options.openId!) parameters.set('openId', options.openId!)
} }
if (options.subAppId != null) { if (options.subAppId != null) {
parameters.set('subAppId', options.subAppId!) parameters.set('subAppId', options.subAppId!)
} }
if (options.subMchId != null) { if (options.subMchId != null) {
parameters.set('subMchId', options.subMchId!) parameters.set('subMchId', options.subMchId!)
} }
let reg = new WXOpenBusinessViewReq(); let reg = new WXOpenBusinessViewReq();
reg.businessType = "requestMerchantTransfer" reg.businessType = "requestMerchantTransfer"
let query = WxpayManager.buildQueryString(parameters) ?? "" let query = WxpayManager.buildQueryString(parameters) ?? ""
reg.query = query reg.query = query
//函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调onResp //函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调onResp
WXApi.send(reg) WXApi.send(reg)
} }
} }
//@brief 发送一个sendReq后,收到微信的回应 //@brief 发送一个sendReq后,收到微信的回应
onResp(resp : BaseResp) { onResp(resp : BaseResp) {
if (resp instanceof WXOpenBusinessViewResp) { if (resp instanceof WXOpenBusinessViewResp) {
let resp = resp as WXOpenBusinessViewResp let resp = resp as WXOpenBusinessViewResp
@@ -178,6 +178,6 @@ class WxpayManager implements WXApiDelegate {
WxpayManager.options?.success?.(res) WxpayManager.options?.success?.(res)
WxpayManager.options?.complete?.(res) WxpayManager.options?.complete?.(res)
} }
} }
} }
} }
File diff suppressed because it is too large Load Diff