day12小程序api使用以及實(shí)現(xiàn)登錄講義_第1頁(yè)
day12小程序api使用以及實(shí)現(xiàn)登錄講義_第2頁(yè)
day12小程序api使用以及實(shí)現(xiàn)登錄講義_第3頁(yè)
day12小程序api使用以及實(shí)現(xiàn)登錄講義_第4頁(yè)
day12小程序api使用以及實(shí)現(xiàn)登錄講義_第5頁(yè)
已閱讀5頁(yè),還剩27頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

小程序網(wǎng)絡(luò)api的使用小程序api的使用小程序相機(jī)api的使用1 、每 小程序需要事先設(shè)置一個(gè)通訊,小程序只可以跟指定的與進(jìn)行網(wǎng)絡(luò)通信。包括普通請(qǐng)求(wx.request)、上傳文件(wx.uploadFile)、文件(wx.downloadFile)和WebSocket通用法:RequestTaskwx.request(ObjectObject是否否設(shè)置請(qǐng)求的header,header中不能設(shè)置Referer。content-type默認(rèn)為否否否否否否data最終發(fā)送給服務(wù)器的數(shù)據(jù)是String類(lèi)型,如果傳入的data不是String類(lèi)型,會(huì)被轉(zhuǎn)換成String。轉(zhuǎn)換規(guī)則如對(duì)于GET方法的數(shù)據(jù),會(huì)將數(shù)據(jù)轉(zhuǎn)換成query() ( (、object.method

的數(shù)據(jù),會(huì)對(duì)數(shù)據(jù)進(jìn)行JSON序 的數(shù)據(jù),會(huì)將值HTTPHTTPHTTPHTTPHTTPHTTPHTTPHTTP、object.dataType值返回的數(shù)據(jù)為JSON,返回后會(huì)對(duì)返回的數(shù)據(jù)進(jìn)行一次不對(duì)返回的內(nèi)容進(jìn)行、object.responseType值響應(yīng)的數(shù)據(jù)為、object.success參數(shù)ObjectHTTPHTTPResponse112345<swiperindicator-dots="true" y="true"interval="3000"<swiper-item<imagesrc="{{item.original}}"123456789title:'加載中url:'success(res){images:}{}、小程序?qū)ebSocket做了支持,文檔地址:/miniprogram/dev/api/wx.connec<inputname="url"value="ws://:18081/ws/1001"bindinput<buttonsize='mini'type="warn">斷開(kāi)連接<buttonsize='mini'type="primary"bindtap="connectSocket">開(kāi)啟連接</button><textareaceholder="輸入發(fā)送內(nèi)容"bindinput<buttonsize='mini'type="primary"bindtap="sendMsg">發(fā)送</button>8<viewwx:for="{{msgs}}">{{index}}:123456789//pages/im/index.js*t_this=this;lettask=wx.connectSocket({task.onMessage(functionletdata=letmsg=data.from.id+","+msgs:[..._this.data.msgs,"接收到消息->"+sk:task,msgs:[..._this.data.msgs,"連接成功urlInput(e){this.surl:{msg:letmsg=this.data.msg;data:msgs:[...this.data.msgs,"發(fā)送消息->"+msg]}、小程序官網(wǎng)并沒(méi)有支持GaphQL,需要通過(guò)第包實(shí)現(xiàn),所以需要通過(guò)nm進(jìn)行管理。首先來(lái)看下在小程序中如何使用nm。 從小程序基礎(chǔ)庫(kù)版本2.2.1或以上、及開(kāi)發(fā)者工具1.02. 或以上開(kāi)始,小程序支持使用npm安裝第1123456//vargql=require('wxapp-graphql');constGraphQL=gql.GraphQL;PS:此處請(qǐng)務(wù)必使用--production選項(xiàng),可以減少安裝一些業(yè)務(wù)無(wú)關(guān)的npm包,從而減少整個(gè)小程序包的npmnpminstallwxapp-graphql-S--789data:onLoad:function(options)//letgql=url:''//url必},gql.query({query:`queryqueryMapHouseData($lng:Float,$lat:Float,$zoom:{MapHouseData(lng:$lng,lat:$lat,zoom:$zoom){{x}}}"lng":"lat":"zoom":}}).then(function(res)}).catch(function(error)}1123456789//varresponseHandler=function(resolve,reject,res,{varretData=res.data.errors?res.data.errors[0].message:{code:200if(res.statusCode==200&&retData.code=={}if(errorHandler)}}}varGraphQL=function(obj,retObj)if(!obj.url)throw"請(qǐng)?zhí)峁〨raphQL請(qǐng)求}retObj=retObj||if{returnquery:function(queryObj)returnnewPromise(function(resolve,{wx.request({url:obj.url,JSON.stringify({:variables://header:obj.header(),complete:function(res){responseHandler(resolve,reject,res,}mutate:function(mutateObj)returnnewPromise(function(resolve,{wx.request({url:obj.url,JSON.stringify({query:variables:mutateObj.variablesheader:obj.header||mutateObj.header,complete:function(res){responseHandler(resolve,reject,}}}}elsereturnfunction(_obj)if(!_obj.body)throw"請(qǐng)?zhí)峁〨raphQL請(qǐng)求}wx.request({obj.url,data:JSON.stringify(_obj.body),success:_obj.success,fail:header:obj.header()||_obj.header(), }}}module.exports{GraphQL:}1//23456789constGraphQL=gql.GraphQL;data:onLoad:function(options)//letgql=url:''//url必},true);query:queryqueryMapHouseData($lng:Float,$lat:Float,$zoom:{MapHouseData(lng:$lng,lat:$lat,zoom:$zoom){{x}}}"lng":"lat":"zoom":}}).then(function(res)}).catch(function(error)}、相關(guān)wx.chooseImage(Object9否否否否否否object.sizeType值object.sourceType值object.success回調(diào)函數(shù)Objectresres.tempFiles本地臨時(shí)文件大小,單位11234567//data:onLoad:function(options)89count:sizeType:['original',sourceType:['album',success(res)}}11<buttonbindtap="chooseImage"size='mini'type="primary">選 wx.previewImage(Object在新頁(yè)面中全屏預(yù)覽。預(yù)覽的過(guò)程中用戶可以進(jìn)行保存、發(fā)送給朋友等操作。參數(shù)Objectobject是需要預(yù)覽的列表。2.2.3起支持urls的第否否否否1123456//data:onLoad:function(options)7chooseImage(){wx.previewImagecurrent: - 接urls: - - - ]//需要預(yù)覽的http列}89文檔:123123456789<viewclass="<viewclass="body-<cameradevice-position="back"flash="off"binderror="error"style="width:100%;height:300px;"></camera><viewclass="btn-<buttontype="primary"bindtap="takePhoto">拍照<viewclass="btn-<buttontype="primary"bindtap="startRecord">開(kāi) <viewclass="btn-<buttontype="primary"bindtap="stopRecord"><viewclass="preview-tips">預(yù)覽<imagewx:if="{{src}}"mode="widthFix"<Src}}"">1234onLoad()this.ctx=56789quality:'high',success:(res)=>{src:}success:(res)=>{}success:(res)=>{src:res.tempThumbPath,Src:res.tempPath}{}1123456789/*pages/demo/index.wxss.preview-{margin:20rpx}.{width:100%;height:300px;}112345.container{y:flex-direction:6align-items:7justify-content:space-8padding:200rpx9box-sizing:border-}pagebackground-color:height:font-size:line-height:}.bodypadding:20rpx}.body-wrapperdisy:flex-direction:align-items:width:}.btn-areamargin-top:box-sizing:border-width:padding:0}效果(需要在真機(jī)上測(cè)試文檔:<view<buttontype="primary"bindtap="scanCode">掃 :小程序中支持了動(dòng)畫(huà)的api,文檔: 調(diào)用wx.login()獲取臨時(shí)登錄憑證code調(diào)用code2Session接口,換取用戶唯一標(biāo)識(shí)OpenID和會(huì)話密鑰session_key之后開(kāi)發(fā)者服務(wù)器可以根據(jù)用戶標(biāo)識(shí)來(lái)生成自定義登錄態(tài),用于后續(xù)業(yè)務(wù)邏輯中前后端交互時(shí)識(shí)別用戶。 是對(duì)用戶數(shù)據(jù)進(jìn)行加密簽名的密鑰。為了應(yīng)用自身的數(shù)據(jù)安全,開(kāi)發(fā)者服務(wù)臨時(shí)登錄憑證code請(qǐng) 11GET1packagecn..haoke.dubbo.api.controller;import importimportorg.springframework.data.redis.core.RedisTemimportimportorg.springframework.web.bind.annotation.PostMapimportorg.springframework.web.bind.annotation.RequestMapimportimportimportorg.springframework.web..RestTemte;importimportimport@RequestMappublicclass{privateRestTemterestTemte;@PostMappublicMap<String,Object>wxLogin(@RequestParam("code")Stringcode)Map<String,Object>result=newresult.put("status",Stringappid=Stringsecret=Stringurl= + +"&secret="+ +"&js_code="+ +StringresData=this.restTemte.getForObject(url,if(StringUtils.contains(resData,"errcode"))//result.put("status",result.put("msg","登錄失敗return Stringticket="HAOKE_"+StringredisKey="WX_LOGIN_"+this.redisTemte.opsForValue().set(redisKey,result.put("data",return}}1123456789packageimportimportimportpublicclassHaoKeConfigpublicRestTemte(){returnnew}

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論