首页 > 编程知识 正文

微信小程序需要https,微信小程序通信协议

时间:2023-05-05 07:29:24 阅读:62572 作者:4702

问题实际上是三个问题:

当微信小程序请求获取SOAP协议格式的数据时,它会将获取的xml解析为可用字符串,并将字符转换为json对象,并提供让接口使用背景查看后台的令人痛心的数据。 作为2010年以后的程序员,即使提供这样的界面,你一眼就什么都不知道的状态吗?是的,没有错,是HTTP请求,但是请求的请求体和响应的响应体,都是SOUP格式的数据。没有多少bb,直接看看怎么处理吧。

根据后台提供的请求格式,微信小程序请求获取SOAP协议格式的数据如下所示:

post/weixin.asmx http/1.1 host : sqlb.myna tapp.cc content-type : text/XML; charset=utf-8内容-长度:长度soap action : ' lib/d zlogin '? XML版本=' 1.0 '编码=' utf-8 '? soap : envelope xmlns 3360 xsi=' http://www.w3.org/2001/XML方案实例' xmlns 3360 xsd=' http://ww.w3.org/XML方案' xmlns 3360 soap=' http://方案. XML soap.org/soap/envelope/' soap 3360 bodydzloginxmlns=' lib ' yhmstrinining 使用soap : body/soap : envelope编写请求通过微信小程序很容易。 我们只需要将上述格式的请求数据连接起来,组合成一个http请求。

soap格式数据getHttpdata: function ()//组装委托人var httpBody='? XML版本=' 1.0 '编码=' utf-8 '? HTP body=' soap 3360 envelope xmlns 3360 xsi=' http://www.w3.org/2001/XML方案实例' xmlns 3360 xsd=' http://ww http httpBody ='dzLogin xmlns='lib '; httpBody =' yhm' '123' '/yhm '; httpBody ='mm' '123' '/mm '; HTP body=' check col ' ' barcode ' '/check col '; HTP body=' OpenID ' ' ok1xq v1h 0q 503 uk7r2quez 8k-h1w ' '/OpenID '; httpBody ='/dzLogin '; httpBody ='/soap:Body '; httpBody ='/soap:Envelope '; wx.request ({ URL : ' https://sqlb.myna tapp.cc/weixin.asmx? op=dzLogin ',data: httpBody,//请求体method: 'POST ',使用POST获取header: { //请求的header'content-type':} “SOAPAction': 'lib/dzLogin”,//来自后台的请求标头包含此数据,因此}, 还要添加success 3360 function { RES } { console }//规则xml数据(、fail: function、fail )、complete: function )、fail 3:

格式化后如下所示。 暂且不论这个借口的数据格式如何,很明显,这样的数据需要进一步提取才能使用。

? XML版本=' 1.0 '编码=' utf-8 '? soap : envelope xmlns 3360 soap=' http://schemas.XML soap.org/soap/envelope/' xmlns 3360 xsi=' 3http://ww.w3.org/org XML方案- instance ' xmlns : xsd=' http://www.w3.org/2001/XML方案' soap 3360 bodydzloginresponsexmlns=' lib ' needexamdzrefcode ' : '0' }/dzloginresult/dzloginresponse/soap 3360 body/soap因此显然,此xml数据分析实际上是DOM 我该怎么办? 很简单。 自己导入说DOM操作的脚本就可以了。 脚本文件来自: https://github.com/jindw/xmldom

用于复制dom.js、dom-parser.js、sax.js和entities.js的新lib文件夹(

准备好后,可以分析数据。

//包var parser=require (' ././lib/DOM-parser.js ' ); //微信请求成功success:function(RES )//新DOM解析对象var parser=new Parser.DOMParser ); //基于请求的XML数据生成DOM对象var xmldoc=parser.parsefromstring (RES.data,' text/xml ' ); 获取//DOM节点的标签是dzLoginResult中的第一个节点对象vardzloginresult=xmldoc.getelementsbytagname (dzloginresult ) )0); //得到节点数据后,天真的铃也是节点,所以使用firstChild.nodeValue。 因为只有天真的铃节点,所以firstChild是天真的铃节点console.log (dzloginresult.first child.nodevalue ) ); //nodeValue询问节点值的json对象varjsond=JSON.parse (dzloginresult.first child.nodevalue ); console.log(jsond[0].dzrefcode; }将字符转换为json对象并在接口中使用的方法如前所述。

转换为//json对象后,可以在开发中使用JSON对象varjsond=JSON.parse (dzloginresult.first child.nodevalue ),下面介绍一下:

JSON.stingify ) )可以将JSON对象或数组转换为JSON格式的字符串

json.parse ()将json格式的字符串转换为json对象或数组

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。