基於thinkPHP實現的微信自定義分享功能示例

2022-09-27 01:54:18 字數 1907 閱讀 7872

分享需要認證微信訂閱號或者服務號.

php **(thinkphp):

$appid='***';

$appsecret='***x';

$timestamp = time();

$noncestr = $this->getrandstr(15);

// dump();

$url = ''. $this->get_token($appid,$appsecret) .'&type=jsapi';

$ret_json = $this->curl_get_contents($url);

$ret = json_decode($ret_json);

$ticket = $ret-> ticket;

//var_dump($ret);

$st程式設計客棧rvalue = 'jsapi_ticket='.$ticket.'&noncestr='.$noncestr.'tamp='.$timestamp.'&url=http://'.$_server['http_host'].$_server['request_uri'];

$signature = sha1($strvalue);

$this->assign('timestamp',$timestamp);

$this->assign('noncestr',$noncestr);

$this->assign('signature',$signature);

function get_token($appid,$appsecret)

}function is_weixin()

return false;

}function getrandstr($length)

return $randstring;

}function curl_get_contents($url)

js**:需要引入:

wx.config(', // 必填,生成簽名的時間戳

noncestr: ''程式設計客棧, // 必填,生成簽名的隨機串

signature: '',// 必填,簽名,見附錄1

jsapilist: ['onmenusharetimeline','onmenushareappmessage'] // 必填,需要使用的js介面列表,所有js介面列表見附錄2

});wx.ready(function()', // 分享標題

link: window.location.href, // 分享鏈結

imgurl: 'http://'+window.location.host+'', // 分享圖示

success: function () ,

cancel: function ()

});wx.onmenushareappmessage(', // 分享標題

desc: removehtmltag(''), // 分享描述

link: window.location.href, // 分享鏈結

imgurl: 'http://'+window.location.host+'', // 分享圖示

type: '', // 分享型別,music、video或link,不填預設為link

dataurl: '', // 如果type是music或video,則要提供資料鏈結,預設為空

success: function () ,

cancel: function ()

}); // config資訊驗證後會執行ready方法,所有介面呼叫都必須在config介面獲得結果之後,config是乙個客戶端的非同步操作,所以如果需要在頁面載入時就呼叫相關介面,則須把相關介面放在ready函式中呼叫來確保正確執行。對於使用者觸發時才呼叫的介面,程式設計客棧則可以直接呼叫,不需要放在ready函式中。

});function removehtmltag(str)

ThinkPHP 沒SDK的微信支付

下面是沒有用官方的sdk 生成預支付訂單 function wechatpay openid,amount,out trade no,body 測試 else public function notify else catch exception exception else class wxpay...

thinkphp5 微信支付微信提現開箱即用

use think db class wxpay extends api parent initialize 獲取預支付訂單 apisummary 獲取預支付訂單 apiparams name token type string required true,description 會員token a...

基於ThinkPHP實現批量刪除

廢話不多說,先上效果圖 html布局 基於bootstrap 留言列表 j ascript window.history.back 返回 j ascript 刪除 id名稱 郵箱內容 日期時間 操作js指令碼處理 使用ajax技術 首先判斷有沒有選中的值,如果沒有則提示 如果有,則傳遞到伺服器端處理...