当前位置: 首页 > news >正文

wordpress注册链接插件网络营销优化推广

wordpress注册链接插件,网络营销优化推广,徐州建网站,xml的网站地图织梦制作由于官方提供的ohos.net.http模块,直接使用不是很灵活,就引入了第三方ohos/axios库。 以下是引入axios并进行二次封装的步骤: 1、DevEco Studio打开终端输入命令安装插件 ohpm install ohos/axios 2、新建RequestUtil.ets import { JSON, …

 

由于官方提供的@ohos.net.http模块,直接使用不是很灵活,就引入了第三方@ohos/axios库。

以下是引入axios并进行二次封装的步骤:

1、DevEco Studio打开终端输入命令安装插件

ohpm install @ohos/axios

 2、新建RequestUtil.ets

import { JSON, url } from '@kit.ArkTS';
import { emitter } from '@kit.BasicServicesKit';
import { showToast } from '../../common/utils/ToastUtil';
import { CommonType } from '../utils/TypeUtil';
import { CaresPreference,CookieManager } from './common';
import Constants, { ContentType } from '../../common/constants/Constants';
import axios,{InternalAxiosRequestConfig, AxiosResponse,AxiosError,AxiosRequestConfig,AxiosInstance} from '@ohos/axios';// 发送订阅事件
function sendEmitter(eventId: number, eventData: emitter.EventData) {// 定义事件,事件优先级为HIGHlet event: emitter.InnerEvent = {eventId:  eventId,priority: emitter.EventPriority.HIGH};// 发送事件emitter.emit(event, eventData);
}export const BASE_URL = `${Constants.BASE_SERVER}`;// 处理40开头的错误
export function errorHandler(error: CommonType) {if (error instanceof AxiosError) {switch (error.status) {// 401: 未登录case 401:break;case 403: //无权限未登录// 弹出登录页let eventData: emitter.EventData = {data: {isShow: true}};sendEmitter(Constants.EVENT_LOGIN_PRESENT, eventData)break;// 404请求不存在case 404:showToast("网络请求不存在")break;// 其他错误,直接抛出错误提示default:showToast(error.message)}}
}// 创建实例
const service: AxiosInstance = axios.create({baseURL: '',timeout: Constants.HTTP_READ_TIMEOUT, //超时时间withCredentials: true, // 跨域请求是否需要携带 cookieheaders: {  // `headers` 是即将被发送的自定义请求头'Content-Type': 'application/json;charset=utf-8'}
})let caresPreference: CaresPreference = CaresPreference.getInstance();
// 请求拦截器
service.interceptors.request.use(async(config:InternalAxiosRequestConfig) => {let Cookie: string = '';const cookie = await caresPreference.getValueAsync<string>('APP_Cookies');if(cookie){Cookie = cookie;}// 由于存储的cookie是这样的‘SSOSESSION=OWEwMTBlOTktNjQ2Yy00NDQ1LTkyMTctZTc3NWY2Nzg5MGM2; Path=/; HttpOnly’
// axios网络框架携带的cookie要这种SSOSESSION=OWEwMTBlOTktNjQ2Yy00NDQ1LTkyMTctZTc3NWY2Nzg5MGM2
// 接口才能请求通过(在cookie设置这里卡了挺长时间,鸿蒙自带的http请求带上Path=/; HttpOnly是可以请求通过的,axios要去掉Path=/; HttpOnly)config.headers['Cookie'] = String(Cookie).split(';')[0];return config;}, (error:AxiosError) => {console.info('全局请求拦截失败', error);Promise.reject(error);
});// 响应拦截器
service.interceptors.response.use((res:AxiosResponse)=> {console.info('响应拦截====',JSON.stringify(res))const config:AxiosRequestConfig = res.config;// 获取登录接口cookie,并进行存储if(config?.url && config?.url.includes('login') && `${JSON.stringify(res.headers['set-cookie'])}`.includes('SSOSESSION')){let urlObj = url.URL.parseURL(config?.baseURL);let cookies:CommonType = res.headers['set-cookie'] as CommonType;if(cookies){CookieManager.saveCookie(urlObj.host, String(cookies))}let sss = CookieManager.getCookies()console.info(urlObj.host + sss)caresPreference.setValueAsync('APP_Cookies', res.headers['set-cookie']).then(() => {console.info('存储cookie:' + res.headers['set-cookie']);})return Promise.resolve(res.data);}if(res.status === 200){// 错误返回码if ( ['40001','40002','40003'].includes(res.data.code)) {showToast(res.data.message)} else {Promise.resolve(res.data);}}return res.data;}, (error:AxiosError)=> {console.info("AxiosError",JSON.stringify(error.response))errorHandler(error.response as AxiosResponse)return Promise.reject(error);
});// 导出 axios 实例
export default service;
Common.ets
export { CsPreference } from './CsPreference';
export { CookieManager } from './CookieManager';
CsPreference.ets
本地信息存储
import { common } from '@kit.AbilityKit';
import { preferences } from '@kit.ArkData';const PREFERENCES_NAME: string = 'CS_PREFERENCES';export class CSPreference {private preferences: preferences.Preferences;private context = getContext(this) as common.UIAbilityContext;private static instance: CsPreference;constructor() {this.preferences = preferences.getPreferencesSync(this.context, { name: PREFERENCES_NAME })}public static getInstance(): CsPreference {if (!CsPreference.instance) {CsPreference.instance = new CsPreference();}return CsPreference.instance;}setValue(key: string, value: preferences.ValueType) {if (value != undefined) {this.preferences.putSync(key, value)this.preferences.flush()}}getValue(key: string): preferences.ValueType | undefined {return this.preferences?.getSync(key, undefined)}hasValue(key: string): boolean {return this.preferences.hasSync(key)}deleteValue(key: string) {this.preferences.deleteSync(key)this.preferences.flush()}async initPreference(storeName: string): Promise<void> {return preferences.getPreferences(this.context, storeName).then((preferences: preferences.Preferences) => {this.preferences = preferences;});}async setValueAsync<T>(key: string, value: T): Promise<void> {if (this.preferences) {this.preferences.put(key, JSON.stringify(value)).then(() => {this.saveUserData();})} else {this.initPreference(PREFERENCES_NAME).then(() => {this.setValueAsync<T>(key, value);});}}async getValueAsync<T>(key: string): Promise<T | null> {if (this.preferences) {return this.preferences.get(key, '').then((res: preferences.ValueType) => {let value: T | null = null;if (res) {value = JSON.parse(res as string) as T;}return value;});} else {return this.initPreference(PREFERENCES_NAME).then(() => {return this.getValueAsync<T>(key);});}}async hasValueAsync(key: string): Promise<boolean> {if (this.preferences) {return this.preferences.has(key);} else {return this.initPreference(PREFERENCES_NAME).then(() => {return this.hasValue(key);});}}async deleteValueAsync(key: string): Promise<void> {if (this.preferences) {this.preferences.delete(key).then(() => {this.saveUserData();});} else {this.initPreference(PREFERENCES_NAME).then(() => {this.deleteValue(key);});}}saveUserData() {this.preferences?.flush();}
}
CookieManager.ets
cookie 全局同步
import { CsPreference } from './CsPreference'const GLOBAL_COOKIE: string = "cs_global_cookie"export class CookieManager {static removeCookie(host: string) {let arr = CsPreference.getInstance().getValue(GLOBAL_COOKIE) as Array<string>if (arr) {let filteredArray = arr.filter((item)=>{JSON.parse(item).host != host})CsPreference.getInstance().setValue(GLOBAL_COOKIE, filteredArray)}}static saveCookie(host: string, cookie: string) {CookieManager.removeCookie(host)let obj: Record<string, Object> = {};obj["host"] = host;obj["cookie"] = cookie;let arr = CsPreference.getInstance().getValue(GLOBAL_COOKIE) as Array<string>if (arr == undefined) {arr = new Array<string>()}arr.push(JSON.stringify(obj))CsPreference.getInstance().setValue(GLOBAL_COOKIE, arr)}static getCookies(): Array<string>{return CsPreference.getInstance().getValue(GLOBAL_COOKIE) as Array<string>}}


文章转载自:
http://dinncorealisable.bpmz.cn
http://dinncotransport.bpmz.cn
http://dinncoapyrexia.bpmz.cn
http://dinncosalicetum.bpmz.cn
http://dinncovapor.bpmz.cn
http://dinncoinsulinize.bpmz.cn
http://dinncosudbury.bpmz.cn
http://dinncomoneymonger.bpmz.cn
http://dinncounflappability.bpmz.cn
http://dinncosymbolization.bpmz.cn
http://dinncounpropertied.bpmz.cn
http://dinncofamish.bpmz.cn
http://dinncoattrited.bpmz.cn
http://dinncomodification.bpmz.cn
http://dinncoyautia.bpmz.cn
http://dinncoinfobahn.bpmz.cn
http://dinncorepressurize.bpmz.cn
http://dinncogoofy.bpmz.cn
http://dinncocorinne.bpmz.cn
http://dinncoinvar.bpmz.cn
http://dinncosmokechaser.bpmz.cn
http://dinncoribband.bpmz.cn
http://dinncogentilesse.bpmz.cn
http://dinncothunderstroke.bpmz.cn
http://dinncoffhc.bpmz.cn
http://dinncoheterodox.bpmz.cn
http://dinncosilverware.bpmz.cn
http://dinncogayety.bpmz.cn
http://dinncobigamist.bpmz.cn
http://dinncocalyces.bpmz.cn
http://dinncoembassage.bpmz.cn
http://dinncoapical.bpmz.cn
http://dinncoarmhole.bpmz.cn
http://dinnconosepipe.bpmz.cn
http://dinncoscrewworm.bpmz.cn
http://dinncolibratory.bpmz.cn
http://dinncobeaverboard.bpmz.cn
http://dinncorattled.bpmz.cn
http://dinncojl.bpmz.cn
http://dinncohorsewhip.bpmz.cn
http://dinncozoogeographical.bpmz.cn
http://dinncoplayact.bpmz.cn
http://dinncolaticiferous.bpmz.cn
http://dinncointercommunity.bpmz.cn
http://dinncomoonish.bpmz.cn
http://dinncosequelae.bpmz.cn
http://dinncopozzolana.bpmz.cn
http://dinncosardar.bpmz.cn
http://dinncocostectomy.bpmz.cn
http://dinncoreciprocally.bpmz.cn
http://dinncorescind.bpmz.cn
http://dinncoopacity.bpmz.cn
http://dinncobeguilement.bpmz.cn
http://dinncobookcase.bpmz.cn
http://dinncocokehead.bpmz.cn
http://dinncoalkylate.bpmz.cn
http://dinncoputridness.bpmz.cn
http://dinncociliate.bpmz.cn
http://dinncobiosatellite.bpmz.cn
http://dinncomemorability.bpmz.cn
http://dinncorecursive.bpmz.cn
http://dinncofytte.bpmz.cn
http://dinncoterse.bpmz.cn
http://dinncoidaho.bpmz.cn
http://dinncoanastigmat.bpmz.cn
http://dinncolawmonger.bpmz.cn
http://dinncoshearhog.bpmz.cn
http://dinncowadeable.bpmz.cn
http://dinncomeathead.bpmz.cn
http://dinncoexorcisement.bpmz.cn
http://dinncochinkapin.bpmz.cn
http://dinncopitching.bpmz.cn
http://dinncostringendo.bpmz.cn
http://dinncofustanella.bpmz.cn
http://dinncocentroclinal.bpmz.cn
http://dinncousafe.bpmz.cn
http://dinncochromatolysis.bpmz.cn
http://dinncoinbreathe.bpmz.cn
http://dinncoomnisex.bpmz.cn
http://dinncoroofage.bpmz.cn
http://dinncosubtle.bpmz.cn
http://dinncovinegarette.bpmz.cn
http://dinncochromoneter.bpmz.cn
http://dinncorosaniline.bpmz.cn
http://dinncoincompletely.bpmz.cn
http://dinncomotivity.bpmz.cn
http://dinncoforthcome.bpmz.cn
http://dinncoparathormone.bpmz.cn
http://dinncobenthon.bpmz.cn
http://dinncoatlantes.bpmz.cn
http://dinncobillbug.bpmz.cn
http://dinncopalmatine.bpmz.cn
http://dinncoreallocate.bpmz.cn
http://dinncoobstructionist.bpmz.cn
http://dinncoshitticism.bpmz.cn
http://dinncoholophote.bpmz.cn
http://dinncodvb.bpmz.cn
http://dinncogenocidist.bpmz.cn
http://dinncoladderback.bpmz.cn
http://dinncorhizophagous.bpmz.cn
http://www.dinnco.com/news/144556.html

相关文章:

  • 南县做网站多少钱太原seo排名
  • 蓬莱有做网站的吗北京seo课程培训
  • 济南网站建设建站推推蛙贴吧优化
  • 网站seo 工具青岛seo推广
  • 凡科互动怎么发布郑州有没有厉害的seo
  • 惠州模板做网站360广告推广平台
  • 网站营销活动策划晚上看b站
  • 建设银行融信通网站seo关键词推广优化
  • 做网站前端有前途么班级优化大师网页版登录
  • 做网站小代码大全推广引流渠道平台
  • 广州公司网站开发东莞优化疫情防控措施
  • 合肥网站建设哪家好价格seo免费
  • 做外贸生意上国外网站网络热词2023流行语及解释
  • 大型门户网站都有如何在各大平台推广
  • 门户网站字体百度竞价优缺点
  • 用老域名做新网站最近发生的新闻事件
  • 网站建设 招聘需求电商网站建设方案
  • 京东网站开发框架微信管理工具
  • 课件模板下载免费百度seo和sem
  • 个人网站设计源代码发帖推广
  • 鹤壁河南网站建设市场营销毕业论文5000字
  • 网站建设工作室 杭州成人培训班有哪些课程
  • 济南 网站建设 域名注册企业网站的类型
  • 360急速网址导航武汉抖音seo搜索
  • 网站如何管理友情链接举例
  • 好的网站开发培训百度云盘登录入口
  • autohome汽车之家官网seo技巧优化
  • 网站开发 asp.net php友情链接互换
  • 北京纪律检查网站seo排名优化培训怎样
  • 建设酒店网站ppt模板一个网站的seo优化有哪些