一、小程序配置
1、微信開發者工具 需要配置不校驗合法域名,否則無法調用本地接口。正式環境部署時需要申請域名、備案,並且申請SSH證書。

2、在主page頁面中.js文件中寫入代碼
// pages/if/if.js Page({ /** * 頁面的初始數據 */ data: { "age":18 }, /** * 生命周期函數--監聽頁面加載 */ onLoad(options) { ////xmlrpc調用odoo數據 // wx.request({method: 'POST', //對xmlrpc來說,GET或者POST都可以 // url: 'http://localhost:8069/xmlrpc/2/common', //這里選擇訪問xmlrpc/2/common,不需要驗證,方便測試 // data: "<?xml version='1.0'?>\n<methodCall>\n<methodName>version</methodName>\n<params>\n</params>\n</methodCall>\n", //xmlrpc的數據格式 // header: {'content-type': 'text/xml' //xmlrpc的內容類型要這么寫 // }, // success (res) {console.log(res.data) //成功獲得值后的操作 // } // }) // //jsonrpc調用odoo數據 // wx.request({ // method: 'POST', //jsonrpc必須使用POST // url: 'http://localhost:8069/jsonrpc', //留意此處地址變化 ,不需要驗證,方便測試 // data: { // "jsonrpc": "2.0", //必要格式,參考下面的網址https://www.odoo.com/documentation/15.0/developer/howtos/backend.html?highlight=jsonrpc // "method": "call", //必要格式,參考下面的網址 // "params": {"service": "common", "method": "version", "args": ''}, //args必須有且不能是null // "id": null, //必要格式,參考下面的網址 // }, // header: { // 'content-type': 'application/json' // 留意此處變化 // }, // success (res) { // console.log(res.data) // console.log(res.data.result.server_version_info) // } // }) // // jsonrpc調用odoo數據,並且帶參數,登陸 // // 參考:https://www.odoo.com/documentation/15.0/developer/howtos/backend.html?highlight=jsonrpc // var args=["odoo15","sunxiao","147258"] // console.log(args) // wx.request({ // method: 'POST', //jsonrpc必須使用POST // url: 'http://localhost:8069/jsonrpc', //留意此處地址變化 ,不需要驗證,方便測試 // data: { // "jsonrpc": "2.0", //必要格式,參考下面的網址https://www.odoo.com/documentation/15.0/developer/howtos/backend.html?highlight=jsonrpc // "method": "call", //必要格式,參考下面的網址 // "params": {"service": "common", "method": "login", "args": args}, //args必須有且不能是null // "id": null, //必要格式,參考下面的網址 // }, // header: { // 'content-type': 'application/json' // 留意此處變化 // }, // success (res) { // console.log(res.data) // } // }) // jsonrpc調用odoo數據,獲取模型partner數據 // 參考:https://www.odoo.com/documentation/15.0/developer/howtos/backend.html?highlight=jsonrpc var args=["odoo15","8","123456","res.partner", "search", [['is_company', '=', true]]] // var args="" console.log(args) wx.request({ method: 'POST', //jsonrpc必須使用POST url: 'http://localhost:8069/jsonrpc', //留意此處地址變化 ,不需要驗證,方便測試 data: { "jsonrpc": "2.0", //必要格式,參考下面的網址https://www.odoo.com/documentation/15.0/developer/howtos/backend.html?highlight=jsonrpc "method": "call", //必要格式,參考下面的網址 "params": {"service": "object", "method": "execute", "args": args}, //args必須有且不能是null "id": null, //必要格式,參考下面的網址 }, header: { 'content-type': 'application/json' // 留意此處變化 }, success (res) { console.log(res.data) } }) }, /** * 生命周期函數--監聽頁面初次渲染完成 */ onReady() { }, /** * 生命周期函數--監聽頁面顯示 */ onShow() { }, /** * 生命周期函數--監聽頁面隱藏 */ onHide() { }, /** * 生命周期函數--監聽頁面卸載 */ onUnload() { }, /** * 頁面相關事件處理函數--監聽用戶下拉動作 */ onPullDownRefresh() { }, /** * 頁面上拉觸底事件的處理函數 */ onReachBottom() { }, /** * 用戶點擊右上角分享 */ onShareAppMessage() { } })
二、odoo參考資料
1、API參考
https://www.odoo.com/documentation/15.0/developer/misc/api/odoo.html?highlight=xmlrpc
2、Webservice
https://www.odoo.com/documentation/15.0/developer/howtos/backend.html?highlight=jsonrpc#
打開網址后,參考目錄
