HarmonyOS 鸿蒙Next 在支付宝PC网页支付时跳转页面栈异常
HarmonyOS 鸿蒙Next 在支付宝PC网页支付时跳转页面栈异常
Web({ src: "", controller: this.controller })
.layoutWeight(1)
.mediaPlayGestureAccess(false)// 设置自动
.width('100%')
.onControllerAttached(()=>{
this.controller.loadUrl(this.linkUrl)
})
// import {
// ContactsDataBase,
// DATA_BASE_KEY,
// GlobalContext,
// NamespaceCommon,
// PreferencesUtil,
// PreferencesUtilConstants,
// StyleConstants,
// TitleBar,
// JSBridge,
// Logger,
// FaultEmptyController,
// CommonConstant,
// extractFileExtension,
// extractFileNameAndExtension
// } from ‘common’
import JSBridge from ‘…/utils/JsBridge’
import web_webview from ‘@ohos.web.webview’
import router from ‘@ohos.router’
import business_error, { BusinessError } from ‘@ohos.base’;
import url from ‘@ohos.url’
import { picker } from ‘@kit.CoreFileKit’;
import fs from ‘@ohos.file.fs’;
interface IOpenBy{
linkUrl: string,
title?:string
}
struct WebPage {
controller: web_webview.WebviewController = new web_webview.WebviewController()
private jsBridge: JSBridge = new JSBridge(this.controller);
@State private showBackButton: boolean | undefined = undefined
@State private showTitleBar: boolean | undefined = false
@State private showBar: boolean = false
@State private config: boolean = false
@State private title: string = ‘’
@State private linkUrl: string = ‘’
@State private pageEnd: boolean = false
responseweb: WebResourceResponse = new WebResourceResponse()
heads: Header[] = new Array()
@State currentPath: string = ‘’
async onPageShow() {
<span class="hljs-keyword"><span class="hljs-keyword">try</span></span> {
<span class="hljs-keyword"><span class="hljs-keyword">const</span></span> cookie = await web_webview.WebCookieManager.fetchCookie(<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.linkUrl)
} <span class="hljs-keyword"><span class="hljs-keyword">catch</span></span> (error) {
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
<span class="hljs-comment"><span class="hljs-comment">//</span></span>
<span class="hljs-comment"><span class="hljs-comment">// const isREFRESH = GlobalContext.getContext().getObject(CommonConstant.WEB_BACK_REFRESH);</span></span>
<span class="hljs-comment"><span class="hljs-comment">// if (isREFRESH) {</span></span>
<span class="hljs-comment"><span class="hljs-comment">// this.controller.refresh();</span></span>
<span class="hljs-comment"><span class="hljs-comment">// GlobalContext.getContext().setObject(CommonConstant.WEB_BACK_REFRESH, false);</span></span>
<span class="hljs-comment"><span class="hljs-comment">// }</span></span>
}
aboutToAppear() {
web_webview.WebviewController.setWebDebuggingAccess(<span class="hljs-literal"><span class="hljs-literal">true</span></span>);
<span class="hljs-comment"><span class="hljs-comment">//|| params?.config?.showBackButton 删掉了,逻辑不对</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">const</span></span> params = router.getParams() as IOpenBy
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (params?.linkUrl) {
<span class="hljs-keyword"><span class="hljs-keyword">const</span></span> urlObject = url.URL.parseURL(params?.linkUrl);
<span class="hljs-keyword"><span class="hljs-keyword">const</span></span> paramsObject = <span class="hljs-keyword"><span class="hljs-keyword">new</span></span> url.URLParams(urlObject.search.slice(<span class="hljs-number"><span class="hljs-number">1</span></span>));
paramsObject.append(<span class="hljs-string"><span class="hljs-string">'activiIsAPP'</span></span>, <span class="hljs-string"><span class="hljs-string">'true'</span></span>)
<span class="hljs-keyword"><span class="hljs-keyword">const</span></span> paramsString = paramsObject.toString()
<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.linkUrl = `${urlObject.origin}${urlObject.pathname}?${paramsString}`
<span class="hljs-comment"><span class="hljs-comment">// this.linkUrl = 'http://10.10.9.43:3032'</span></span>
<span class="hljs-comment"><span class="hljs-comment">// this.linkUrl = this.linkUrl.replace('https://um.zhongheschool.com', 'http://10.10.9.167:3032')</span></span>
}
}
// 当用户点击返回按钮时触发
onBackPress() {
<span class="hljs-keyword"><span class="hljs-keyword">try</span></span> {
<span class="hljs-comment"><span class="hljs-comment">// 获取当前h5的历史记录</span></span>
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> result = <span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.controller.accessBackward();
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (result) {
<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.controller.backward();
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> <span class="hljs-literal"><span class="hljs-literal">true</span></span>
} <span class="hljs-keyword"><span class="hljs-keyword">else</span></span> {
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> <span class="hljs-literal"><span class="hljs-literal">false</span></span>
}
} <span class="hljs-keyword"><span class="hljs-keyword">catch</span></span> (error) {
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> <span class="hljs-literal"><span class="hljs-literal">false</span></span>
}
}
build() {
Column() {
Web({ src: <span class="hljs-string"><span class="hljs-string">""</span></span>, controller: <span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.controller })
.layoutWeight(<span class="hljs-number"><span class="hljs-number">1</span></span>)
.mediaPlayGestureAccess(<span class="hljs-literal"><span class="hljs-literal">false</span></span>)<span class="hljs-comment"><span class="hljs-comment">// 设置自动</span></span>
.width(<span class="hljs-string"><span class="hljs-string">'100%'</span></span>)
.onControllerAttached(()=>{
<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.controller.loadUrl(<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.linkUrl)
})
.onShowFileSelector((event) => {
console.log(<span class="hljs-string"><span class="hljs-string">'MyFileUploader onShowFileSelector invoked'</span></span>)
<span class="hljs-keyword"><span class="hljs-keyword">try</span></span> {
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> PhotoSelectOptions = <span class="hljs-keyword"><span class="hljs-keyword">new</span></span> picker.PhotoSelectOptions();
PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
PhotoSelectOptions.maxSelectNumber = <span class="hljs-number"><span class="hljs-number">1</span></span>;
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> photoPicker = <span class="hljs-keyword"><span class="hljs-keyword">new</span></span> picker.PhotoViewPicker();
photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: picker.PhotoSelectResult) => {
console.info(<span class="hljs-string"><span class="hljs-string">'PhotoViewPicker.select successfully, PhotoSelectResult uri: '</span></span> + <span class="hljs-built_in"><span class="hljs-built_in">JSON</span></span>.stringify(PhotoSelectResult));
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (event) {
event.result.handleFileList(PhotoSelectResult.photoUris);
}
}).catch((err: BusinessError) => {
console.error(<span class="hljs-string"><span class="hljs-string">'PhotoViewPicker.select failed with err: '</span></span> + <span class="hljs-built_in"><span class="hljs-built_in">JSON</span></span>.stringify(err));
});
} <span class="hljs-keyword"><span class="hljs-keyword">catch</span></span> (error) {
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> err: BusinessError = error as BusinessError;
console.error(<span class="hljs-string"><span class="hljs-string">'PhotoViewPicker failed with err: '</span></span> + <span class="hljs-built_in"><span class="hljs-built_in">JSON</span></span>.stringify(err));
}
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> <span class="hljs-literal"><span class="hljs-literal">true</span></span>
})
.javaScriptAccess(<span class="hljs-literal"><span class="hljs-literal">true</span></span>)<span class="hljs-comment"><span class="hljs-comment">//设置是否允许执行JavaScript脚本</span></span>
.domStorageAccess(<span class="hljs-literal"><span class="hljs-literal">true</span></span>)<span class="hljs-comment"><span class="hljs-comment">//设置是否开启文档对象模型存储接口(DOM Storage API)权限,默认未开启。</span></span>
.mixedMode(MixedMode.None)<span class="hljs-comment"><span class="hljs-comment">//设置是否允许加载超文本传输协议(HTTP)和超文本传输安全协议(HTTPS)混合内容,默认不允许加载HTTP和HTTPS混合内容。</span></span>
.zoomAccess(<span class="hljs-literal"><span class="hljs-literal">false</span></span>)<span class="hljs-comment"><span class="hljs-comment">//设置是否支持手势进行缩放,默认允许执行缩放。</span></span>
.horizontalScrollBarAccess(<span class="hljs-literal"><span class="hljs-literal">false</span></span>)<span class="hljs-comment"><span class="hljs-comment">//设置是否显示横向滚动条,包括系统默认滚动条和用户自定义滚动条。默认显示。</span></span>
.verticalScrollBarAccess(<span class="hljs-literal"><span class="hljs-literal">false</span></span>)<span class="hljs-comment"><span class="hljs-comment">//设置是否显示纵向滚动条,包括系统默认滚动条和用户自定义滚动条。默认显示。</span></span>
.cacheMode(CacheMode.Default)<span class="hljs-comment"><span class="hljs-comment">//缓存模式</span></span>
.javaScriptProxy(<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.jsBridge.javaScriptProxy)
.onConsole((event) => {
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (event) {
<span class="hljs-comment"><span class="hljs-comment">// Logger.debug('H5 日志 getSourceId:' + event.message.getSourceId())</span></span>
<span class="hljs-comment"><span class="hljs-comment">// Logger.debug('H5 日志getLineNumber:' + event.message.getLineNumber())</span></span>
<span class="hljs-comment"><span class="hljs-comment">// Logger.debug('H5 日志 getMessageLevel:' + event.message.getMessageLevel())</span></span>
}
<span class="hljs-keyword"><span class="hljs-keyword">return</span></span> <span class="hljs-literal"><span class="hljs-literal">false</span></span>
})
.onPageBegin(async () => {
<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.jsBridge.initJsBridge();
})
.onPageEnd(async (e) => {
<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.pageEnd = <span class="hljs-literal"><span class="hljs-literal">true</span></span>
})
.onTitleReceive((event) => {
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (event?.title.startsWith(<span class="hljs-string"><span class="hljs-string">"http:"</span></span>) || event?.title.startsWith(<span class="hljs-string"><span class="hljs-string">"https:"</span></span>) || event?.title.includes(<span class="hljs-string"><span class="hljs-string">"com"</span></span>)) {
<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.title = <span class="hljs-string"><span class="hljs-string">''</span></span>
} <span class="hljs-keyword"><span class="hljs-keyword">else</span></span> {
<span class="hljs-keyword"><span class="hljs-keyword">const</span></span> params = router.getParams() as IOpenBy
<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.title = event?.title ? event.title : (params.title || <span class="hljs-string"><span class="hljs-string">''</span></span>)
}
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (<span class="hljs-keyword"><span class="hljs-keyword">this</span></span>.pageEnd == <span class="hljs-literal"><span class="hljs-literal">true</span></span>) {
<span class="hljs-comment"><span class="hljs-comment">// this.setTitleBarConfig()</span></span>
}
})
.onErrorReceive((event) => {
<span class="hljs-keyword"><span class="hljs-keyword">if</span></span> (event) {
console.log(<span class="hljs-string"><span class="hljs-string">'getErrorInfo:'</span></span> + event.error.getErrorInfo())
console.log(<span class="hljs-string"><span class="hljs-string">'getErrorCode:'</span></span> + event.error.getErrorCode())
console.log(<span class="hljs-string"><span class="hljs-string">'url:'</span></span> + event.request.getRequestUrl())
console.log(<span class="hljs-string"><span class="hljs-string">'isMainFrame:'</span></span> + event.request.isMainFrame())
console.log(<span class="hljs-string"><span class="hljs-string">'isRedirect:'</span></span> + event.request.isRedirect())
console.log(<span class="hljs-string"><span class="hljs-string">'isRequestGesture:'</span></span> + event.request.isRequestGesture())
console.log(<span class="hljs-string"><span class="hljs-string">'getRequestHeader_headerKey:'</span></span> + event.request.getRequestHeader().toString())
<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> result = event.request.getRequestHeader()
console.log(<span class="hljs-string"><span class="hljs-string">'The request header result size is '</span></span> + result.length)
<span class="hljs-keyword"><span class="hljs-keyword">for</span></span> (<span class="hljs-keyword"><span class="hljs-keyword">let</span></span> i of result) {
console.log(<span class="hljs-string"><span class="hljs-string">'The request header key is : '</span></span> + i.headerKey + <span class="hljs-string"><span class="hljs-string">', value is : '</span></span> + i.headerValue)
}
}
})
}.width(<span class="hljs-string"><span class="hljs-string">'100%'</span></span>)
.height(<span class="hljs-string"><span class="hljs-string">'100%'</span></span>)
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
针对HarmonyOS 鸿蒙Next在支付宝PC网页支付时跳转页面栈异常的问题,这通常是由于系统或支付平台在处理页面跳转时的逻辑错误或兼容性问题所致。以下是一些可能的解决方案:
- 确认页面路径:确保在支付宝PC网页支付时,页面路径正确无误,避免路径错误导致的跳转异常。
- 更新系统或支付平台:检查HarmonyOS 鸿蒙Next系统和支付宝PC网页支付平台是否为最新版本,确保两者之间的兼容性。
- 使用正确的跳转方法:在HarmonyOS 鸿蒙Next中,确保使用了正确的页面跳转方法,如pushNamedRoute等,避免跳转方法不当导致的页面栈异常。
如果上述方法均无法解决问题,可能是由于更深层次的系统或支付平台问题所致。此时,建议直接联系HarmonyOS鸿蒙Next的官方客服或支付宝的官方客服,获取更专业的帮助。官网地址是:https://www.itying.com/category-93-b0.html ,以便尽快解决问题。