html页面纯php原生编写微信分享修改标题和图标
来源:互联网 发布:js react触发ajax 编辑:程序博客网 时间:2024/06/01 08:49
<!DOCTYPE html>
<?php
////access token
if(strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger"))
{
if(!isset($GLOBALS['access_token']) || !isset($GLOBALS['effectivetm'])|| (time() - $GLOBALS['effectiveTokentm']) >3600 )
{
$appid = "******************";
$appsecret = "************************";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$access_token = $jsoninfo["access_token"];
$effectiveTokentm = time();
//setcookie("access_token", $access_token, time()+3600);
}
echo $GLOBALS['access_token'];
echo "====<br />";
////ticket
if(!isset($GLOBALS['ticket']) || !isset($GLOBALS['effectiveTickettm']) || (time() - $GLOBALS['effectiveTickettm']) > 3600)
{
$token =$GLOBALS['access_token'];
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$ticket = $jsoninfo["ticket"];
$effectiveTickettm = time();
//setcookie("ticket", $ticket, time()+3600);
}
}
echo $GLOBALS['ticket'];
echo "====<br />";
////nonceStr
function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
////sign package 签名url必须动态获取
function getSignPackage() {
if(strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger"))
{
$jsapiTicket = $GLOBALS['ticket'];
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$ddstring = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
echo $ddstring."=====<br />";
$signature = sha1($ddstring);
$signPackage = array("appId" => '***********', "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url, "signature" => $signature, "rawString" => $string);
return $signPackage;
}
return null;
}
$packdata = getSignPackage();
print_r($packdata);
?>
<html prefix="og: http://ogp.me/ns#" class="csstransforms csstransforms3d csstransitions js_active vc_desktop vc_transform vc_transform vc_transform " id="ls-global" lang="zh-CN"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>weixin fenxiang DESCANDICON</title>
<!-- weixin begin -->
<?php
if(strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger")){
echo '<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"> </script>';
}else{
echo '<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"> </script>';
}
?>
<script>
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '***********', // 必填,公众号的唯一标识
timestamp: "<?php echo $packdata['timestamp'] ?>", // 必填,生成签名的时间戳
nonceStr: '<?php echo $packdata['nonceStr'] ?>',//'15dbdf29c2d34416', // 必填,生成签名的随机串
signature: '<?php echo $packdata['signature'] ?>',// 必填,签名,见附录1
jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function () {
alert("00000");
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
console.log('ready');
wx.onMenuShareAppMessage({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
alert(1);
console.log('成功1');
},
cancel: function () {
// 用户取消分享后执行的回调函数
alert(2);
console.log('失败');
}
});
wx.onMenuShareTimeline({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
console.log('成功1');
alert("2222");
},
cancel: function () {
// 用户取消分享后执行的回调函数
console.log('失败');
alert("3333");
}
});
wx.onMenuShareQQ({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
console.log('成功1');
},
cancel: function () {
// 用户取消分享后执行的回调函数
console.log('失败');
}
});
wx.onMenuShareWeibo({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
console.log('成功1');
},
cancel: function () {
// 用户取消分享后执行的回调函数
console.log('失败');
}
});
wx.onMenuShareQZone({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
console.log('成功1');
},
cancel: function () {
// 用户取消分享后执行的回调函数
console.log('失败');
}
});
});
wx.error(function (res) {
alert("00000ERROR");
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
console.log('error');
});
wx.checkJsApi({
jsApiList: ['chooseImage'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function (res) {
alert("11111");
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
console.log('check');
}
});
</script>
<!-- weixin end -->
<body >
<?php
if(strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger")){
echo "您正在使用微信浏览器访问该页面";
}else{
echo "<span>HTTP/1.1 401 Unauthorized</span>";
}
<?php
////access token
if(strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger"))
{
if(!isset($GLOBALS['access_token']) || !isset($GLOBALS['effectivetm'])|| (time() - $GLOBALS['effectiveTokentm']) >3600 )
{
$appid = "******************";
$appsecret = "************************";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$access_token = $jsoninfo["access_token"];
$effectiveTokentm = time();
//setcookie("access_token", $access_token, time()+3600);
}
echo $GLOBALS['access_token'];
echo "====<br />";
////ticket
if(!isset($GLOBALS['ticket']) || !isset($GLOBALS['effectiveTickettm']) || (time() - $GLOBALS['effectiveTickettm']) > 3600)
{
$token =$GLOBALS['access_token'];
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$ticket = $jsoninfo["ticket"];
$effectiveTickettm = time();
//setcookie("ticket", $ticket, time()+3600);
}
}
echo $GLOBALS['ticket'];
echo "====<br />";
////nonceStr
function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
////sign package 签名url必须动态获取
function getSignPackage() {
if(strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger"))
{
$jsapiTicket = $GLOBALS['ticket'];
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$ddstring = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
echo $ddstring."=====<br />";
$signature = sha1($ddstring);
$signPackage = array("appId" => '***********', "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url, "signature" => $signature, "rawString" => $string);
return $signPackage;
}
return null;
}
$packdata = getSignPackage();
print_r($packdata);
?>
<html prefix="og: http://ogp.me/ns#" class="csstransforms csstransforms3d csstransitions js_active vc_desktop vc_transform vc_transform vc_transform " id="ls-global" lang="zh-CN"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>weixin fenxiang DESCANDICON</title>
<!-- weixin begin -->
<?php
if(strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger")){
echo '<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"> </script>';
}else{
echo '<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"> </script>';
}
?>
<script>
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '***********', // 必填,公众号的唯一标识
timestamp: "<?php echo $packdata['timestamp'] ?>", // 必填,生成签名的时间戳
nonceStr: '<?php echo $packdata['nonceStr'] ?>',//'15dbdf29c2d34416', // 必填,生成签名的随机串
signature: '<?php echo $packdata['signature'] ?>',// 必填,签名,见附录1
jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function () {
alert("00000");
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
console.log('ready');
wx.onMenuShareAppMessage({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
alert(1);
console.log('成功1');
},
cancel: function () {
// 用户取消分享后执行的回调函数
alert(2);
console.log('失败');
}
});
wx.onMenuShareTimeline({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
console.log('成功1');
alert("2222");
},
cancel: function () {
// 用户取消分享后执行的回调函数
console.log('失败');
alert("3333");
}
});
wx.onMenuShareQQ({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
console.log('成功1');
},
cancel: function () {
// 用户取消分享后执行的回调函数
console.log('失败');
}
});
wx.onMenuShareWeibo({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
console.log('成功1');
},
cancel: function () {
// 用户取消分享后执行的回调函数
console.log('失败');
}
});
wx.onMenuShareQZone({
title: '5周年', // 分享标题
desc: '5周年', // 分享描述
link: 'http://www.baidu.com?', // 分享链接
imgUrl: 'http://www.baidu.com/1111.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
console.log('成功1');
},
cancel: function () {
// 用户取消分享后执行的回调函数
console.log('失败');
}
});
});
wx.error(function (res) {
alert("00000ERROR");
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
console.log('error');
});
wx.checkJsApi({
jsApiList: ['chooseImage'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function (res) {
alert("11111");
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
console.log('check');
}
});
</script>
<!-- weixin end -->
<body >
<?php
if(strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger")){
echo "您正在使用微信浏览器访问该页面";
}else{
echo "<span>HTTP/1.1 401 Unauthorized</span>";
}
?>
<p>坑1:签名时url必须动态获取</p>
<p>坑2:jsApiList接口顺序必须按照微信公司规定来</p>
<a href="#" id="toTop" style="display: none;"><span id="undefined"></span>undefined</a>
</body>
</html>
阅读全文
0 0
- html页面纯php原生编写微信分享修改标题和图标
- 微信开发--微信分享自定义图标和标题
- 微信分享朋友圈分享代码自定义标题、说明、图标和分享链接
- 【iOS】原生微信登录和分享
- ios微信和QQ原生分享
- 微信JS-SDK 修改分享标题 分享图片
- 微信开发-分享页面修改
- 微信分享标题和图片设置
- 微信Web页面开发——自定义分享标题和缩略图
- javascript实现修改微信分享的标题内容等
- php 微信分享自定义标题 图片 描述接口开发
- 修改jsp页面标题左边的图标
- iOS微信分享&h5和原生app交互
- 第三方网站接入微信JS-SDK的分享自定义设置,微信分享小图标以及标题
- 如何修改手机端分享网页给微信好友和朋友圈显示的图片和标题
- html(h5)页面实现微信js分享
- html静态页面实现微信分享思路
- html静态页面实现微信分享思路
- 快速幂,矩阵快速幂原理介绍
- ie8及其以下版本兼容性问题之响应式
- [RK3288][Android6.0] WiFi的dts配置说明(AP6335)
- Varjo要实现人眼级别分辨率,宣称秒杀市面上所有头显
- 我是如何做测试项目管理的
- html页面纯php原生编写微信分享修改标题和图标
- Activiti核心架构之职责链与命令模式
- 程序员如何用高逼格科学把妹法则
- 数据库连接丢失,重连 Cause: java.sql.SQLException: Could not retrieve transation read-only status server
- js 同步加载 异步加载 延迟加载 预加载
- 数据库设计
- Python list
- [转]同步synchronized方法和代码块
- Maven生命周期和插件