12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292 |
- !(function (win, doc) {
- var iosWebviewHasReady = false
- win._iosWebviewReadyCallback = function () {
- iosWebviewHasReady = true
- if (myBridge.fnList.length) {
- myBridge.fnList.forEach(function (fn) {
- myBridge.invoke(fn)
- })
- }
- }
- //判断访问终端
- var browser = {
- versions: function () {
- var u = navigator.userAgent, app = navigator.appVersion;
- return {
- trident: u.indexOf('Trident') > -1, //IE内核
- presto: u.indexOf('Presto') > -1, //opera内核
- webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
- gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
- mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
- ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
- android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
- iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
- iPad: u.indexOf('iPad') > -1, //是否iPad
- webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
- weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)
- qq: u.match(/\sQQ/i) == " qq" //是否QQ
- };
- }(),
- language: (navigator.browserLanguage || navigator.language).toLowerCase()
- }
- var myBridge = {
- fnList: [],
- invoke: function (command) {
- console.log('invoke');
- console.log(browser.versions)
- console.log(navigator.userAgent)
- console.log(navigator.appVersion)
- try {
- if (browser.versions.android) {
- console.log('android');
- if (window.ytBridge) {
- window.ytBridge.invoke(command)
- } else {
- throw new Error(false)
- }
- } else if (browser.versions.ios) {
- console.log('ios');
- // WKWebview 内核的ios app 交互方式
- if (win.webkit && win.webkit.messageHandlers) {
- console.log('ios1')
- window.webkit.messageHandlers.invoke.postMessage(command);
- } else if (win.ytBridge) {
- console.log('ios2')
- // UIWebview 内核的ios app交互方式
- // window.ytBridge.invoke(command)
- if (window.ytBridge) {
- window.ytBridge.invoke(command)
- } else {
- throw new Error(false)
- }
- } else {
- console.log('ios3')
- this.fnList.push(command)
- throw new Error(false)
- }
- } else {
- console.log('error1111');
- // window.ytBridge.invoke(command)
- // console.log(window.ytBridge)
- if (win.webkit && win.webkit.messageHandlers) {
- console.log('ios000')
- window.webkit.messageHandlers.invoke.postMessage(command);
- } else if (win.ytBridge) {
- console.log('ios11');
- if (window.ytBridge) {
- console.log('ios111');
- window.ytBridge.invoke(command)
- } else {
- console.log('ios222');
- throw new Error(false)
- }
- } else {
- console.log('ios22');
- throw new Error(false)
- }
- }
- } catch (e) {
- throw new Error(false)
- }
- }
- }
- // 供native调用的回调函数队列
- var _js2nativeCallbackList = win._js2nativeCallbackList = []
- // 分享单例对象
- var shareInfo = {}
- var userInfo = {};
- var areaInfo = {};
- var locationInfo = {};
- var fontInfo = {};
- var keyboardInfo = {};
- var scanInfo = {};
- var payInfo = {};
- var payWayInfo = {};
- var recordInfo = {};
- var backInfo = {};
- var downInfo = {};
- var fliesInfo = {};
- var collectionInfo = {};
- var unCollectionInfo = {};
- var grayPlacement = {};
- var smUserInfo = {};
- var isLoginInfo = {}
- var ArticleActionInfo = {};
- var phoneMsgInfo = {};
- var jsSDK = {
- version: '2.0.0',
- /**
- * 设置分享内容
- * @param {Object} options 分享的参数信息
- */
- onShare: function (options) {
- /**
- * 加入一个时间戳,后续回调发生的时候可以通过时间戳判断回调是否过期,比如用户多次调用onShare
- * @type {[type]}
- */
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== shareInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- shareInfo.cancel && shareInfo.cancel()
- break
- case 200:
- shareInfo.success && shareInfo.success()
- break
- case 400:
- shareInfo.error && shareInfo.error()
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- shareInfo = options
- var num = _js2nativeCallbackList.push(callback)
- shareInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- shareInfo.methodName = 'setShareConfig'
- var command = JSON.stringify(shareInfo)
- myBridge.invoke(command)
- },
- /**
- * 发起分享
- */
- share: function () {
- var command = JSON.stringify({
- methodName: 'share'
- })
- myBridge.invoke(command)
- },
- /**
- * 唤起app端登录
- */
- login: function () {
- var command = JSON.stringify({
- methodName: 'login'
- })
- myBridge.invoke(command)
- },
- /**
- * 唤起app端支付,更具type区分支付类型
- * @param {Number} type 资源类型(以下列出部分,具体请找接口或app端获取)
- * 3:专辑 4:单曲 5:活动-5:活动外链6:图文资讯-6:图文资讯外链8:直播栏目9:直播节目单 10:视频直播11:视频点播
- * 12:主持人数据,前五名打赏排行榜14:微信矩阵19:话题20:网页(链接)24:投票 25:福利26:购物 27:回听
- * 29:内容 30:红包 34:短音频33:视频合集41:问答详情38:问答专家61:UGC直播间62:专辑合集
- * @param {Number} id 资源id
- */
- onPay: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== shareInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- shareInfo.cancel && shareInfo.cancel()
- break
- case 200:
- shareInfo.success && shareInfo.success()
- break
- case 400:
- shareInfo.error && shareInfo.error()
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- shareInfo = options
- var num = _js2nativeCallbackList.push(callback)
- shareInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- shareInfo.methodName = 'pay'
- var command = JSON.stringify(shareInfo)
- myBridge.invoke(command)
- },
- /**
- * 唤起app内跳转,根据type(值同上)
- * @param {Number} type 资源类型 目前支持:3专辑 6图文资讯 -6:图文资讯外链 87:打开新webview页面
- * @param {Number} id 资源id
- * @param {String} title 标题 (用于分享) type:87 为导航栏标题
- * @param {String} imgUrl 图片(用于分享)
- * @param {String} color 颜色值,支持#FFFFFF格式 type: 87为修改导航栏颜色
- * @param {String} url 链接地址
- */
- onJump: function (options) {
- options.methodName = 'jump'
- var command = JSON.stringify(options)
- myBridge.invoke(command)
- },
- onJumpCode: function (options) {
- var command = JSON.stringify({
- methodName: 'jumpCode',
- code: options.code,
- id: options.id
- })
- myBridge.invoke(command)
- },
- getFlies: function (options) {
- console.log('getFlies---------------------')
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== fliesInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- fliesInfo.cancel && fliesInfo.cancel(res)
- break
- case 200:
- fliesInfo.success && fliesInfo.success(res)
- break
- case 400:
- fliesInfo.error && fliesInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- fliesInfo = options
- var num = _js2nativeCallbackList.push(callback)
- fliesInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- fliesInfo.methodName = 'getFlies'
- var command = JSON.stringify(fliesInfo)
- myBridge.invoke(command)
- },
- collection: function (options) {
- console.log('collection---------------------')
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== collectionInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- collectionInfo.cancel && collectionInfo.cancel(res)
- break
- case 200:
- collectionInfo.success && collectionInfo.success(res)
- break
- case 400:
- collectionInfo.error && collectionInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- collectionInfo = options
- var num = _js2nativeCallbackList.push(callback)
- collectionInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- collectionInfo.methodName = 'collection'
- var command = JSON.stringify(collectionInfo)
- myBridge.invoke(command)
- },
- unCollection: function (options) {
- console.log('collection---------------------')
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== unCollectionInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- unCollectionInfo.cancel && unCollectionInfo.cancel(res)
- break
- case 200:
- unCollectionInfo.success && unCollectionInfo.success(res)
- break
- case 400:
- unCollectionInfo.error && unCollectionInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- unCollectionInfo = options
- var num = _js2nativeCallbackList.push(callback)
- unCollectionInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- unCollectionInfo.methodName = 'unCollection'
- var command = JSON.stringify(unCollectionInfo)
- myBridge.invoke(command)
- },
- getUserInfo: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== userInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- userInfo.cancel && userInfo.cancel(res)
- break
- case 200:
- userInfo.success && userInfo.success(res)
- break
- case 400:
- userInfo.error && userInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- userInfo = options
- var num = _js2nativeCallbackList.push(callback)
- userInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- userInfo.methodName = 'getUserInfo'
- var command = JSON.stringify(userInfo)
- myBridge.invoke(command)
- },
- getSmUserInfo: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== smUserInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- smUserInfo.cancel && smUserInfo.cancel(res)
- break
- case 200:
- smUserInfo.success && smUserInfo.success(res)
- break
- case 400:
- smUserInfo.error && smUserInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- smUserInfo = options
- var num = _js2nativeCallbackList.push(callback)
- smUserInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- smUserInfo.methodName = 'getSmUserInfo'
- var command = JSON.stringify(smUserInfo)
- myBridge.invoke(command)
- },
- getGrayPlacement: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== grayPlacement.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- console.log('res+++++++++++++++++', res)
- switch (res.code) {
- case 100:
- grayPlacement.cancel && grayPlacement.cancel(res)
- break
- case 200:
- grayPlacement.success && grayPlacement.success(res)
- break
- case 400:
- grayPlacement.error && grayPlacement.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- grayPlacement = options
- var num = _js2nativeCallbackList.push(callback)
- grayPlacement.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- grayPlacement.methodName = 'getGrayPlacement'
- var command = JSON.stringify(grayPlacement)
- myBridge.invoke(command)
- },
- getAreaInfo: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== areaInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- areaInfo.cancel && areaInfo.cancel(res)
- break
- case 200:
- areaInfo.success && areaInfo.success(res)
- break
- case 400:
- areaInfo.error && areaInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- areaInfo = options
- var num = _js2nativeCallbackList.push(callback)
- areaInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- areaInfo.methodName = 'getAreaInfo'
- var command = JSON.stringify(areaInfo)
- myBridge.invoke(command)
- },
- /**
- * 设置导航栏标题
- * @param {String} title 标题内容 setTitle({title: xxx})
- */
- setTitle: function (options) {
- options.methodName = 'setTitle'
- var command = JSON.stringify(options)
- myBridge.invoke(command)
- },
- /**
- * 获取app当前gps定位坐标
- * geolocation({success: res => {}})
- */
- geolocation: function (options) {
- console.log('geolocation')
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== locationInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- locationInfo.cancel && locationInfo.cancel(res)
- break
- case 200:
- locationInfo.success && locationInfo.success(res)
- break
- case 400:
- locationInfo.error && locationInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- locationInfo = options
- var num = _js2nativeCallbackList.push(callback)
- locationInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- locationInfo.methodName = 'geolocation'
- var command = JSON.stringify(locationInfo)
- myBridge.invoke(command)
- },
- /**
- * 获取字体大小范围
- * getFontSize({success: res => {}})
- * 1:大 2:中 3: 正常 4:大 5:特大
- */
- getFontSize: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== fontInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- fontInfo.cancel && fontInfo.cancel(res)
- break
- case 200:
- fontInfo.success && fontInfo.success(res)
- break
- case 400:
- fontInfo.error && fontInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- fontInfo = options
- var num = _js2nativeCallbackList.push(callback)
- fontInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- fontInfo.methodName = 'getFontSize'
- var command = JSON.stringify(fontInfo)
- myBridge.invoke(command)
- },
-
- /**
- * 获取键盘高度
- * getKeyboardHeight({success: res => {}})
- *
- */
- getKeyboardHeight: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== keyboardInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- keyboardInfo.cancel && keyboardInfo.cancel(res)
- break
- case 200:
- keyboardInfo.success && keyboardInfo.success(res)
- break
- case 400:
- keyboardInfo.error && keyboardInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- keyboardInfo = options
- var num = _js2nativeCallbackList.push(callback)
- keyboardInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- keyboardInfo.methodName = 'getKeyboardHeight'
- var command = JSON.stringify(keyboardInfo)
- myBridge.invoke(command)
- },
- /**
- * 唤起app端认证
- */
- auth: function () {
- var command = JSON.stringify({
- methodName: 'auth'
- })
- myBridge.invoke(command)
- },
- /**
- * 设置导航栏颜色
- * @param {String} color 颜色值 setTitle({color: '#FFF'})
- */
- setNavColor: function (options) {
- options.methodName = 'navColor'
- var command = JSON.stringify(options)
- myBridge.invoke(command)
- },
- /**
- * 唤起app扫码
- * scan({success: res => {res.text}})
- */
- scan: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== scanInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- scanInfo.cancel && scanInfo.cancel(res)
- break
- case 200:
- scanInfo.success && scanInfo.success(res)
- break
- case 400:
- scanInfo.error && scanInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- scanInfo = options
- var num = _js2nativeCallbackList.push(callback)
- scanInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- scanInfo.methodName = 'scan'
- var command = JSON.stringify(scanInfo)
- myBridge.invoke(command)
- },
- /**
- * 唤起app端支付方式选择,返回已选的支付方式1:支付宝 2:微信
- * @param {String} content 支付信息内容[物业缴费]
- * @param {Number} price 支付金额,单位 元
- * yt.payWay({content: '物业缴费', price: 10, success (res) { // res.type} })
- */
- payWay: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- // console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== payWayInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- payWayInfo.cancel && payWayInfo.cancel(res)
- break
- case 200:
- payWayInfo.success && payWayInfo.success(res)
- break
- case 400:
- payWayInfo.error && payWayInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- payWayInfo = options
- var num = _js2nativeCallbackList.push(callback)
- payWayInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- payWayInfo.methodName = 'payWay'
- var command = JSON.stringify(payWayInfo)
- myBridge.invoke(command)
- },
- /**
- * 唤起app端支付,此为通用支付,需要将支付信息传给app端
- * @param {type} type 支付类型 1:支付宝 2:微信
- * @param {String} alipayOrderNo 支付宝所需参数
- * @param {Object} wetChat 微信支付所需信息 yt.generalPay({type: 2, wetChat: {appId: 'xxx', nonceStr: '', partnerid: '', paySign: '', prepayId: '', signType: 'MD5', timeStamp: ''}, success () => {}})
- * yt.generalPay({type: 1, alipayOrderNo: 'xxxx', success () => {}})
- */
- generalPay: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== payInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- payInfo.cancel && payInfo.cancel(res)
- break
- case 200:
- payInfo.success && payInfo.success(res)
- break
- case 400:
- payInfo.error && payInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- payInfo = options
- var num = _js2nativeCallbackList.push(callback)
- payInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- payInfo.methodName = 'generalPay'
- var command = JSON.stringify(payInfo)
- myBridge.invoke(command)
- },
- /**
- * 调用app的录音功能
- * @param {type} type 录音执行的方法 start:开始录音 end:停止录音 onEnd:监听录音结束(主动结束录音||设置到达最大录音时长时,会自动结束||也监听一些报错信息)
- * play:播放(播放的是app中录音的缓存文件) pause:暂停 stop: 停止播放 onPlayEnd: 监听播放结束 save:保存(app会上传文件,然后返回已上传的地址)
- * @param {Number} maxDuration 最大录音时间,倒计时结束则触发停止录音
- * @param {String} url 录音缓存文件路径,用于播放
- * @param {String} src 上传保存后的绝对路径 https://xxx.mp3
- * @return {Object} duration:录音的时长 url:录音缓存文件路径,用于播放
- * yt.record({type: 'start', maxDuration: 300, success () => {}})
- * yt.record({type: 'end', success (res) => {code: 200, duration: 48, url: 'xxxx'}})
- * yt.record({type: 'onEnd', success (res) => {code: 200, duration: 48, url: 'xxxx'}})
- * yt.record({type: 'play', url: 'xxxx', success (res) => {})
- * yt.record({type: 'pause', url: 'xxxx', success (res) => {})
- * yt.record({type: 'stop', url: 'xxxx', success (res) => {})
- * yt.record({type: 'onPlayEnd', url: 'xxxx', success (res) => {})
- * yt.record({type: 'save', url: 'xxxx', success (res) => {code: 200, src: 'https://xxx.mp3'})
- */
- record: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- if (options.type === 'start' && !options.maxDuration) {
- options.error && options.error({ msg: '请填写最大录音时长' })
- return
- }
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- // console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== recordInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- recordInfo.cancel && recordInfo.cancel(res)
- break
- case 200:
- recordInfo.success && recordInfo.success(res)
- break
- case 400:
- recordInfo.error && recordInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- recordInfo = options
- var num = _js2nativeCallbackList.push(callback)
- recordInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- recordInfo.methodName = 'record'
- var command = JSON.stringify(recordInfo)
- myBridge.invoke(command)
- },
- /**
- * 关闭app中当前webview页面,返回到上一页, 龙游通app1.9.0版本开始支持,云听版本对应4.8.0
- * window.yt.back({ success: res => {}, error: res => {}, cancel: res => {} })
- */
- back: function (options = {}) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- // console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== backInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- backInfo.cancel && backInfo.cancel(res)
- break
- case 200:
- backInfo.success && backInfo.success(res)
- break
- case 400:
- backInfo.error && backInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- backInfo = options
- var num = _js2nativeCallbackList.push(callback)
- backInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- backInfo.methodName = 'back'
- var command = JSON.stringify(backInfo)
- myBridge.invoke(command)
- },
- /**
- * 下载附件, 龙游通app2.2.0版本开始支持,云听版本对应4.11.0
- * @param {String} url 下载的附件(word,excel,pdf,图片)地址
- * @param {String} name 下载的附件名称,需要有对应的文件类型后缀
- * window.yt.downloadFile({ url: 'xxx.pdf', name: 'xxx.doc', success: res => {}, error: res => {}, cancel: res => {} })
- */
- downloadFile: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- // console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== downInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- downInfo.cancel && downInfo.cancel(res)
- break
- case 200:
- downInfo.success && downInfo.success(res)
- break
- case 400:
- downInfo.error && downInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- downInfo = options
- var num = _js2nativeCallbackList.push(callback)
- downInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- downInfo.methodName = 'downloadFile'
- var command = JSON.stringify(downInfo)
- myBridge.invoke(command)
- },
- /**
- * 跳转打开小程序页面,目前只有app中支持,5.3.0开始支持
- * @param { String } originId 小程序原始id(可在小程序后台查看)
- * @param { String } path 小程序页面具体路径 /pages/index/index.html?xxx
- * window.yt.jumpWxMiniProgram({ originId: 'gh_4bfdd5c85f15', path: '/pages/index/index.html?xxx' })
- */
- jumpWxMiniProgram: function (options = {}) {
- options.methodName = 'jumpWxMiniProgram'
- var command = JSON.stringify(options)
- myBridge.invoke(command)
- },
- isLogin: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- // console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== isLoginInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- isLoginInfo.cancel && isLoginInfo.cancel(res)
- break
- case 200:
- isLoginInfo.success && isLoginInfo.success(res)
- break
- case 400:
- isLoginInfo.error && isLoginInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- isLoginInfo = options
- var num = _js2nativeCallbackList.push(callback)
- isLoginInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- isLoginInfo.methodName = 'isLogin'
- var command = JSON.stringify(isLoginInfo)
- myBridge.invoke(command)
- },
- getUserToken: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- // console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== isLoginInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- isLoginInfo.cancel && isLoginInfo.cancel(res)
- break
- case 200:
- isLoginInfo.success && isLoginInfo.success(res)
- break
- case 400:
- isLoginInfo.error && isLoginInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- isLoginInfo = options
- var num = _js2nativeCallbackList.push(callback)
- isLoginInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- isLoginInfo.methodName = 'getUserToken'
- var command = JSON.stringify(isLoginInfo)
- myBridge.invoke(command)
- },
- getArticleAction: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== ArticleActionInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- ArticleActionInfo.cancel && ArticleActionInfo.cancel(res)
- break
- case 200:
- ArticleActionInfo.success && ArticleActionInfo.success(res)
- break
- case 400:
- ArticleActionInfo.error && ArticleActionInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- ArticleActionInfo = options
- var num = _js2nativeCallbackList.push(callback)
- ArticleActionInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- ArticleActionInfo.methodName = 'getArticleAction'
- var command = JSON.stringify(ArticleActionInfo)
- myBridge.invoke(command)
- },
- getPhoneMsg: function (options) {
- var timestamp = Date.now()
- options.timestamp = timestamp
- /**
- * 定义一个通用的回调函数,接收来自native端传递的参数,根据参数再来回调这边的成功、失败等回调
- * @param {[object]} res [native传递的参数]
- * @return {Function} [回调函数]
- */
- var callback = function (res) {
- // console.log("native response :" + (typeof res === 'string' ? res : JSON.stringify(res)))
- if (res) {
- if (callback.timestamp !== phoneMsgInfo.timestamp) {
- console.warn('callback expired')
- return
- }
- /**
- * 如果传入的几个回调不是函数,将会导致错误
- */
- try {
- switch (res.code) {
- case 100:
- phoneMsgInfo.cancel && phoneMsgInfo.cancel(res)
- break
- case 200:
- phoneMsgInfo.success && phoneMsgInfo.success(res)
- break
- case 400:
- phoneMsgInfo.error && phoneMsgInfo.error(res)
- break
- }
- } catch (error) {
- console.error(error)
- }
- }
- }
- callback.timestamp = timestamp
- phoneMsgInfo = options
- var num = _js2nativeCallbackList.push(callback)
- phoneMsgInfo.callback = '_js2nativeCallbackList[' + (num - 1) + ']'
- phoneMsgInfo.methodName = 'getPhoneMsg'
- var command = JSON.stringify(phoneMsgInfo)
- myBridge.invoke(command)
- },
- }
- win.yt = jsSDK
- })(window, document);
|