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",
"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"
></up-image>
微信登录
</view>
<view v-if="!isIOS" class="login_other_item" @click="alipayOneLogin">
</view>
<view class="login_other_item" @click="aa">
<!-- <view v-if="!isIOS" class="login_other_item" @click="alipayOneLogin"> -->
<up-image
src="/static/login/ZFB.png"
width="44"
@@ -202,7 +203,20 @@ export default {
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() {
// const sysPlatform = getCurrentSysPlatform();
// if(sysPlatform === "android"){
@@ -23,19 +23,19 @@
### 示例:
```javascript
uni.requestMerchantTransfer({
"mchId": "mchId",
"appId": "微信开发者平台对应app的APPID",
"package": "package",
success: (res) => {
console.log(res)
},
fail: (res) => {
console.log(res.errMsg)
},
complete: (res) => {
console.log(res.errMsg)
}
uni.requestMerchantTransfer({
"mchId": "mchId",
"appId": "微信开发者平台对应app的APPID",
"package": "package",
success: (res) => {
console.log(res)
},
fail: (res) => {
console.log(res.errMsg)
},
complete: (res) => {
console.log(res.errMsg)
}
})
```
@@ -48,32 +48,32 @@ iOS平台必须在项目根目录下的 [Info.plist](https://uniapp.dcloud.net.c
示例如下:
```xml
<?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>WeChat</key>
<dict>
<key>appid</key>
<string>请填写微信开发者平台对应app的APPID</string>
<key>universalLink</key>
<string>请填写能唤起当前应用的Universal Links路径</string>
</dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>WeChat</string>
<key>CFBundleURLSchemes</key>
<array>
<string>请填写微信开发者平台对应app的APPID</string>
</array>
</dict>
</array>
</dict>
<?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>WeChat</key>
<dict>
<key>appid</key>
<string>请填写微信开发者平台对应app的APPID</string>
<key>universalLink</key>
<string>请填写能唤起当前应用的Universal Links路径</string>
</dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>WeChat</string>
<key>CFBundleURLSchemes</key>
<array>
<string>请填写微信开发者平台对应app的APPID</string>
</array>
</dict>
</array>
</dict>
</plist>
```
@@ -1,11 +1,11 @@
{
"frameworks": [
"CoreGraphics.framework",
"WebKit.framework",
"Security.framework"
],
"deploymentTarget": "12",
"plists": {
"LSApplicationQueriesSchemes": ["weixin", "weixinULAPI", "weixinURLParamsAPI"]
}
{
"frameworks": [
"CoreGraphics.framework",
"WebKit.framework",
"Security.framework"
],
"deploymentTarget": "12",
"plists": {
"LSApplicationQueriesSchemes": ["weixin", "weixinULAPI", "weixinURLParamsAPI"]
}
}
@@ -1,158 +1,158 @@
import { UIApplication } from "UIKit";
import { URL, NSUserActivity, Bundle, URLComponents, URLQueryItem, Script } from "Foundation";
import { RequestMerchantTransfer, RequestMerchantTransferOptions, RequestMerchantTransferGeneralCallbackResult } from '../interface.uts';
export const requestMerchantTransfer : RequestMerchantTransfer = function (options : RequestMerchantTransferOptions) {
WxpayManager.requestMerchantTransfer(options)
}
export class WxpayManagerHookProxy implements UTSiOSHookProxy {
// 应用正常启动时 (不包括已在后台转到前台的情况)的回调函数。
applicationDidFinishLaunchingWithOptions(application : UIApplication | null, launchOptions : Map<UIApplication.LaunchOptionsKey, any> | null = null) : boolean {
WxpayManager.registerApp()
return false
}
// 通过 url scheme 方式唤起 app 时的回调函数。
applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map<UIApplication.OpenURLOptionsKey, any> | null = null) : boolean {
WxpayManager.handleOpen(url)
return true
}
// 当应用程序接收到与用户活动相关的数据时调用此方法,例如,当用户使用 Universal Link 唤起应用时。
applicationContinueUserActivityRestorationHandler(application : UIApplication | null, userActivity : NSUserActivity | null, restorationHandler : ((res : [any] | null) => void) | null = null) : boolean {
WxpayManager.handleOpenUniversalLink(userActivity)
return true
}
}
class WxpayManager implements WXApiDelegate {
private static shared = new WxpayManager()
private static options ?: RequestMerchantTransferOptions
@UTSiOS.keyword("fileprivate")
static registerApp() {
const scheme = WxpayManager.getApplicationScheme()
const universalLink = WxpayManager.getApplicationUniversalLink()
if (scheme != null && scheme != "" && universalLink != null && universalLink != "") {
WXApi.registerApp(scheme!, universalLink = universalLink!)
}
}
@UTSiOS.keyword("fileprivate")
static handleOpen(url : URL) {
WXApi.handleOpen(url, delegate = shared)
}
@UTSiOS.keyword("fileprivate")
static handleOpenUniversalLink(userActivity : NSUserActivity | null) {
if (userActivity != null) {
WXApi.handleOpenUniversalLink(userActivity!, delegate = shared)
}
}
private static getApplicationScheme() : string | null {
let scheme : string | null = null
const infoDictionary = Bundle.main.infoDictionary
if (infoDictionary != null) {
const wechat = infoDictionary!['WeChat'] as Map<string, any> | null
if (wechat != null) {
scheme = wechat!['appid'] as string | null
}
}
return scheme
}
private static getApplicationUniversalLink() : string | null {
let universalLink : string | null = null
const infoDictionary = Bundle.main.infoDictionary
if (infoDictionary != null) {
const wechat = infoDictionary!['WeChat'] as Map<string, any> | null
if (wechat != null) {
universalLink = wechat!['universalLink'] as string | null
}
}
return universalLink
}
//@brief 检查微信是否已被用户安装
@UTSiOS.keyword("fileprivate")
static isWXAppInstalled() : boolean {
const url = URL(string = "weixin://")!
if (UIApplication.shared.canOpenURL(url)) {
return true
}
return false
}
static buildQueryString(parameters : Map<string, string>) : string | null {
let components = URLComponents()
let queryItems : [URLQueryItem] = []
parameters.forEach((value, key) => {
queryItems.append(URLQueryItem(name = key, value = value))
})
components.queryItems = queryItems
return components.percentEncodedQuery
}
static requestMerchantTransfer(options : RequestMerchantTransferOptions) {
WxpayManager.options = options
if (WxpayManager.isWXAppInstalled() == false) {
var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '微信没有安装'
}
options.fail?.(res)
options.complete?.(res)
}
if (WxpayManager.getApplicationScheme() == null || WxpayManager.getApplicationScheme() == "") {
var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '没有配置对应的URL Scheme'
}
options.fail?.(res)
options.complete?.(res)
return
}
if (WxpayManager.getApplicationUniversalLink() == null || WxpayManager.getApplicationUniversalLink() == "") {
var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '没有配置对应的Universal Link'
}
options.fail?.(res)
options.complete?.(res)
return
}
if (WxpayManager.options != null) {
const parameters = new Map<string, string>()
parameters.set('mchId', options.mchId)
parameters.set('package', options.package)
if (options.appId != null) {
parameters.set('appId', options.appId!)
}
if (options.openId != null) {
parameters.set('openId', options.openId!)
}
if (options.subAppId != null) {
parameters.set('subAppId', options.subAppId!)
}
if (options.subMchId != null) {
parameters.set('subMchId', options.subMchId!)
}
let reg = new WXOpenBusinessViewReq();
reg.businessType = "requestMerchantTransfer"
let query = WxpayManager.buildQueryString(parameters) ?? ""
reg.query = query
//函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调onResp
WXApi.send(reg)
}
}
//@brief 发送一个sendReq后,收到微信的回应
import { UIApplication } from "UIKit";
import { URL, NSUserActivity, Bundle, URLComponents, URLQueryItem, Script } from "Foundation";
import { RequestMerchantTransfer, RequestMerchantTransferOptions, RequestMerchantTransferGeneralCallbackResult } from '../interface.uts';
export const requestMerchantTransfer : RequestMerchantTransfer = function (options : RequestMerchantTransferOptions) {
WxpayManager.requestMerchantTransfer(options)
}
export class WxpayManagerHookProxy implements UTSiOSHookProxy {
// 应用正常启动时 (不包括已在后台转到前台的情况)的回调函数。
applicationDidFinishLaunchingWithOptions(application : UIApplication | null, launchOptions : Map<UIApplication.LaunchOptionsKey, any> | null = null) : boolean {
WxpayManager.registerApp()
return false
}
// 通过 url scheme 方式唤起 app 时的回调函数。
applicationOpenURLOptions(app : UIApplication | null, url : URL, options : Map<UIApplication.OpenURLOptionsKey, any> | null = null) : boolean {
WxpayManager.handleOpen(url)
return true
}
// 当应用程序接收到与用户活动相关的数据时调用此方法,例如,当用户使用 Universal Link 唤起应用时。
applicationContinueUserActivityRestorationHandler(application : UIApplication | null, userActivity : NSUserActivity | null, restorationHandler : ((res : [any] | null) => void) | null = null) : boolean {
WxpayManager.handleOpenUniversalLink(userActivity)
return true
}
}
class WxpayManager implements WXApiDelegate {
private static shared = new WxpayManager()
private static options ?: RequestMerchantTransferOptions
@UTSiOS.keyword("fileprivate")
static registerApp() {
const scheme = WxpayManager.getApplicationScheme()
const universalLink = WxpayManager.getApplicationUniversalLink()
if (scheme != null && scheme != "" && universalLink != null && universalLink != "") {
WXApi.registerApp(scheme!, universalLink = universalLink!)
}
}
@UTSiOS.keyword("fileprivate")
static handleOpen(url : URL) {
WXApi.handleOpen(url, delegate = shared)
}
@UTSiOS.keyword("fileprivate")
static handleOpenUniversalLink(userActivity : NSUserActivity | null) {
if (userActivity != null) {
WXApi.handleOpenUniversalLink(userActivity!, delegate = shared)
}
}
private static getApplicationScheme() : string | null {
let scheme : string | null = null
const infoDictionary = Bundle.main.infoDictionary
if (infoDictionary != null) {
const wechat = infoDictionary!['WeChat'] as Map<string, any> | null
if (wechat != null) {
scheme = wechat!['appid'] as string | null
}
}
return scheme
}
private static getApplicationUniversalLink() : string | null {
let universalLink : string | null = null
const infoDictionary = Bundle.main.infoDictionary
if (infoDictionary != null) {
const wechat = infoDictionary!['WeChat'] as Map<string, any> | null
if (wechat != null) {
universalLink = wechat!['universalLink'] as string | null
}
}
return universalLink
}
//@brief 检查微信是否已被用户安装
@UTSiOS.keyword("fileprivate")
static isWXAppInstalled() : boolean {
const url = URL(string = "weixin://")!
if (UIApplication.shared.canOpenURL(url)) {
return true
}
return false
}
static buildQueryString(parameters : Map<string, string>) : string | null {
let components = URLComponents()
let queryItems : [URLQueryItem] = []
parameters.forEach((value, key) => {
queryItems.append(URLQueryItem(name = key, value = value))
})
components.queryItems = queryItems
return components.percentEncodedQuery
}
static requestMerchantTransfer(options : RequestMerchantTransferOptions) {
WxpayManager.options = options
if (WxpayManager.isWXAppInstalled() == false) {
var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '微信没有安装'
}
options.fail?.(res)
options.complete?.(res)
}
if (WxpayManager.getApplicationScheme() == null || WxpayManager.getApplicationScheme() == "") {
var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '没有配置对应的URL Scheme'
}
options.fail?.(res)
options.complete?.(res)
return
}
if (WxpayManager.getApplicationUniversalLink() == null || WxpayManager.getApplicationUniversalLink() == "") {
var res : RequestMerchantTransferGeneralCallbackResult = {
errMsg: '没有配置对应的Universal Link'
}
options.fail?.(res)
options.complete?.(res)
return
}
if (WxpayManager.options != null) {
const parameters = new Map<string, string>()
parameters.set('mchId', options.mchId)
parameters.set('package', options.package)
if (options.appId != null) {
parameters.set('appId', options.appId!)
}
if (options.openId != null) {
parameters.set('openId', options.openId!)
}
if (options.subAppId != null) {
parameters.set('subAppId', options.subAppId!)
}
if (options.subMchId != null) {
parameters.set('subMchId', options.subMchId!)
}
let reg = new WXOpenBusinessViewReq();
reg.businessType = "requestMerchantTransfer"
let query = WxpayManager.buildQueryString(parameters) ?? ""
reg.query = query
//函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调onResp
WXApi.send(reg)
}
}
//@brief 发送一个sendReq后,收到微信的回应
onResp(resp : BaseResp) {
if (resp instanceof WXOpenBusinessViewResp) {
let resp = resp as WXOpenBusinessViewResp
@@ -178,6 +178,6 @@ class WxpayManager implements WXApiDelegate {
WxpayManager.options?.success?.(res)
WxpayManager.options?.complete?.(res)
}
}
}
}
}
}
File diff suppressed because it is too large Load Diff