大神們,php服務號開發,有沒有好的圖片上傳外掛程式推薦。自己找個圖片上傳外掛程式,端不怎麼支。
回複內容:
大神們,php服務號開發,有沒有好的圖片上傳外掛程式推薦。自己找個圖片上傳外掛程式,端不怎麼支。
這個一般都是用自己的js-sdk
外掛程式,的策略是:
配置`js-sdk`,成功後調用介面比如:拍照、圖片選擇、圖片上傳,當然圖片是上傳到伺服器的,然後你需要做的是在程式後端利用上傳返回的`meidia_id`來下載上傳的圖片,這樣就不需要自己找外掛程式了,而且你自己找的外掛程式上也不會支援的;
wx.config({ debug: false, // 開啟偵錯模式,調用的所有api的傳回值會在用戶端alert出來,若要查看傳入的參數,可以在pc端開啟,參數資訊會通過log打出,僅在pc端時才會列印。 appId: '{$appid}', // 必填,公眾號的唯一標識 timestamp: "{$timestamp}", // 必填,產生簽名的時間戳記 nonceStr: '{$noncestr}', // 必填,產生簽名的隨機串 signature: '{$signature}',// 必填,簽名,見附錄1 jsApiList: ['chooseImage','previewImage','uploadImage'] // 必填,需要使用的JS介面列表,所有JS介面列表見附錄2 }); $(".box-fill").each(function(){ var ele = $(this); $(this).click(function(){ wx.chooseImage({ count: 1, // 預設9 sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,預設二者都有 sourceType: ['album', 'camera'], // 可以指定來源是相簿還是相機,預設二者都有 success: function (res) { var localIds = res.localIds; // 返回選定照片的本地ID列表,localId可以作為img標籤的src屬性顯示圖片 var $imgStr = ""; ele.html($imgStr); wx.uploadImage({ localId: localIds.toString(), // 需要上傳的圖片的本地ID,由chooseImage介面獲得 isShowProgressTips: 1, // 預設為1,顯示進度提示 success: function (res) { var serverId = res.serverId; // 返回圖片的伺服器端ID uploadServerId(serverId, ele.data('type')); } }); } }); }) }) /** * 上傳服務id,也就是可以在伺服器下載圖片的media_id * @param serverId * @param type 上傳圖片類型 */ function uploadServerId(serverId, type){ $.post("{:U('uploadServerId')}", {openId: "{$openid}", serverId: serverId, type: type},function(ret){ if(ret.status == -1){ alert(ret.msg); }else if(ret.status == 1){ if(ret.finish){ $(".filters").hide(); } }else{ alert('請關閉頁面後重新登陸上傳!'); } }) }
另外,建議你去公眾平台看下js-sdk的開發文檔,因為這涉及到了後端的一些東西,要求部分資訊需要在服務端完成,而不是在前端