我是小站长 發表於 2019-6-1 16:41:46

discuz X2中DIY的第三方C/S扩展

*************************************************<br />** 本教程基于版本:Discuz! X 2.0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;**<br />*************************************************<br /><br />在 <strong>论坛后台</strong> → <strong>门户</strong> → <strong>第三访模块</strong> <br />添加第三方模块,后台需要填写以下选项<br /><br /><strong>第三方地址</strong>: 输入 第三方模块的 URL 地址,第三方返回的内容必须 XML 模块的格式<br /><strong>客户端ID</strong>: 此ID由数据源方提供<br /><strong>签名加密方式</strong>: 目前支持MD5加密方式,也可以不使用签名,由数据源方提供<br /><strong>通信密钥</strong>: 从 URL 地址获得数据时的密钥,如果数据源不需要密钥可以为空。此密钥由数据源方提供<br /><br /><br />提交的时候程序会使用 import_block 函数 去服务端请求配置 <br /><br />其间 该函数会调用 create_sign_url 函数 生成签名<ol><li>function create_sign_url($para, $key = '', $signtype = ''){<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ksort($para);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$url = http_build_query($para);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(!empty($signtype) &amp;&amp; strtoupper($signtype) == 'MD5') {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $sign = md5(urldecode($url).$key);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $url = $url.'&amp;sign='.$sign;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} else {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $url = $url.'&amp;sign='.$key;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return $url;<br /><li>}<br /><li></ol>create_sign_url 会将第一个参数 url 参数的数组 $para (包括:clientid、op、charset) 用 ksort 排序 <br />然后 用 http_build_query 函数转义生成 url 的参数 连上后台设置的 通信密钥 进行md5加密后生成的 sign<br />然后拼接着请求的参数<br />如charset=gbk&amp;clientid=100000&amp;op=getconfig&amp;sign=ce09add6aaadfcc58f7d6140dc55fa09<br />如果后台没有设置加密方式 sign 为后台设置的通信密钥<br /><br />请求的参数与后台设置的 第三方地址 拼成完成的向第三请求的地址<br />使用dz的 dfsockopen 函数请求第三方服务端<br /><br />服务端需要返回 xml 有 <font style="color:rgb(102,102,102)"><font face="微软雅黑, 宋体,">Title 和 Data </font></font>两部分的配置<br />其中Title分部是固定的且区分大小写:&lt;item id=&quot;Title&quot;&gt;&lt;!]&gt;&lt;/item&gt;<br />Data分部主要包括5个属性:<br />a、version: 版本号(必需)<br />b、name: 模块名(必需)<br />c、fields: 可显示的字段,在模块样式中使用(必需)<br />* name 为该字段的显示名称<br />* formtype 决定编辑单条数据时该字段的显示方式: 类型有: text, textarea, date, title, summary, pic;<br />* datatype 决定该字段的数据展示,类型有: string, int, date, title, summary, pic;<br />d、getsetting: 可设置和接收的参数(必需)<br />* title 为显示的名称<br />* type 为表单类型, 有: text, password, number, textarea, radio, select, mselect, mradio, mcheckbox, calendar;<br />f、style: 内置的显示样式(非必需)<br /><br /><br /><br />前台模块更新 除了向第三方请求数据时除了会以 POST 方式向第三方服务端传递后台设置的参数外 还会以 POST 的方式附加传递以下参数:* op=getdata ,此参数表示客户端要请求数据;<br />* clientid ,客户端ID(服务器分配给客户端的ID);<br />* op=getdata ,此参数表示客户端要请求数据;<br />* items ,为用户指定显示的模块数据条数;<br />* bannedids ,为用户选择屏蔽某数据时记录在模块中的该数据 id,多个 id 以半角分号(,)分隔。 应该在获取数据时屏蔽该数据;<br />* charset,客户端的数据编码<br />* sign ,数据签名,如果服务器端没有设置通信密钥则此值为空<br /><br />第三方服务端返回数据的 data 中应该包含 上面配置中可显示的字段 fields 指定的所有字段。并附加以下字段:* id 标志该数据的 id,如果用户屏蔽某数据时,会将该数据的 id 以 POST 的方式变量名为 bannedids,多个id以半角逗号(,)分隔提交到服务器端<br />* picflag 如果有图片,则该值标志图片的类型,0 为 url、1 为本地、2 为 ftp 远程;如果图片是 Discuz! X 系统中的图片可以情况设置为 1 或 2,其它情况为 0<br />需要注意: 除 id,title, url, pic, picflag, summary 几个字段外,其它字段需要放到 fields 数组里。<br /><br /><br /><br />数据<em>, </em>第三方<em>, </em>参数<em>, </em>模块<em>, </em>字段
頁: [1]
查看完整版本: discuz X2中DIY的第三方C/S扩展