微信

微信

微信公众号图片显示不正常(此图片来自微信公众平台,未经允许不可引用)怎么办?

sisian 回复了问题 • 3 人关注 • 1 个回复 • 3669 次浏览 • 来自相关话题

微信小程序如何实现拨打电话

回复

西贤 回复了问题 • 1 人关注 • 1 个回复 • 1026 次浏览 • 来自相关话题

php实现微信朋友圈分享,自定义标题和图标

sisian 发表了文章 • 0 个评论 • 1947 次浏览 • 来自相关话题

PHP实现微信朋友圈分享自定义图标、标题jsjdk.php (微信官方接口代码) <?php class JSSDK { private $appId; ...查看全部
PHP实现微信朋友圈分享自定义图标、标题
jsjdk.php (微信官方接口代码)

<?php
class JSSDK {

private $appId;
private $appSecret;

public function __construct($appId, $appSecret) {
$this -> appId = $appId;
$this -> appSecret = $appSecret;
}

public function getSignPackage() {
$jsapiTicket = $this -> getJsApiTicket();
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = $this -> createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
$signature = sha1($string);
$signPackage = array("appId" => $this -> appId, "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url, "signature" => $signature, "rawString" => $string);
return $signPackage;
}

private 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;
}

private function getJsApiTicket() {
// jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode(file_get_contents("jsapi_ticket.json"));
if ($data -> expire_time < time()) {
$accessToken = $this -> getAccessToken();
// 如果是企业号用以下 URL 获取 ticket
// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
$res = json_decode($this -> httpGet($url));
$ticket = $res -> ticket;
if ($ticket) {
$data -> expire_time = time() + 7000;
$data -> jsapi_ticket = $ticket;
$fp = fopen("jsapi_ticket.json", "w");
fwrite($fp, json_encode($data));
fclose($fp);
}
} else {
$ticket = $data -> jsapi_ticket;
}

return $ticket;
}

private function getAccessToken() {
// access_token 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode(file_get_contents("access_token.json"));
if ($data -> expire_time < time()) {
// 如果是企业号用以下URL获取access_token
// $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
$res = json_decode($this -> httpGet($url));
$access_token = $res -> access_token;
if ($access_token) {
$data -> expire_time = time() + 7000;
$data -> access_token = $access_token;
$fp = fopen("access_token.json", "w");
fwrite($fp, json_encode($data));
fclose($fp);
}
}else{
$access_token = $data -> access_token;
}
return $access_token;
}

private function httpGet($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
}


 
在jsjdk.php 同级目录创建两个文件,分别是 access_token.json 和 jsapi_ticket.json
 
修改配置信息,使用微信访问就可以正常分享了

index.php

<?php
require_once "jssdk.php";
$jssdk = new JSSDK("开发者ID", "开发者密码");//在微信开发 基本配置里面找到填写
$signPackage = $jssdk->GetSignPackage();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
wx.config({
debug: false,
appId: '<?php echo $signPackage["appId"];?>',
timestamp: <?php echo $signPackage["timestamp"];?>,
nonceStr: '<?php echo $signPackage["nonceStr"];?>',
signature: '<?php echo $signPackage["signature"];?>',
jsApiList: [ //要用的接口必须在这里注册
'onMenuShareTimeline'
]
});
wx.ready(function () {
wx.onMenuShareTimeline({
title: '我是分享显示在微信里边的标题喔', // 分享标题
link: 'http://www.shili.com/arc/65124.html', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'http://img.shili.com/2018/u56841254/share.jpg', // 分享图标
success: function () {
//用户点击了分享后执行的回调函数
}
});

//更多分享接口就不在多写了,详情请查阅 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
});
</script>
</html>
不明白的可以下边留言喔
条新动态, 点击查看
关于引用微信图片网络上很多方法,但是很多都比较复杂或无效
自定义个PHP文件

然后通过自定义PHP文件(getimg.php)获取引用图片

例如:getimg.php文件地址为(http://www.yicix.com/getimg.php)<... 显示全部 »
关于引用微信图片网络上很多方法,但是很多都比较复杂或无效
自定义个PHP文件

然后通过自定义PHP文件(getimg.php)获取引用图片

例如:getimg.php文件地址为(http://www.yicix.com/getimg.php)<img src="http://www.yicix.com/getimg.php?imgurl=默认图片地址"/>

微信公众号图片显示不正常(此图片来自微信公众平台,未经允许不可引用)怎么办?

sisian 回复了问题 • 3 人关注 • 1 个回复 • 3669 次浏览 • 来自相关话题

微信公众号图片显示不正常(此图片来自微信公众平台,未经允许不可引用)怎么办?

回复

sisian 回复了问题 • 3 人关注 • 1 个回复 • 3669 次浏览 • 来自相关话题

微信小程序如何实现拨打电话

回复

西贤 回复了问题 • 1 人关注 • 1 个回复 • 1026 次浏览 • 来自相关话题

php实现微信朋友圈分享,自定义标题和图标

sisian 发表了文章 • 0 个评论 • 1947 次浏览 • 来自相关话题

PHP实现微信朋友圈分享自定义图标、标题jsjdk.php (微信官方接口代码) <?php class JSSDK { private $appId; ...查看全部
PHP实现微信朋友圈分享自定义图标、标题
jsjdk.php (微信官方接口代码)

<?php
class JSSDK {

private $appId;
private $appSecret;

public function __construct($appId, $appSecret) {
$this -> appId = $appId;
$this -> appSecret = $appSecret;
}

public function getSignPackage() {
$jsapiTicket = $this -> getJsApiTicket();
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = $this -> createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
$signature = sha1($string);
$signPackage = array("appId" => $this -> appId, "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url, "signature" => $signature, "rawString" => $string);
return $signPackage;
}

private 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;
}

private function getJsApiTicket() {
// jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode(file_get_contents("jsapi_ticket.json"));
if ($data -> expire_time < time()) {
$accessToken = $this -> getAccessToken();
// 如果是企业号用以下 URL 获取 ticket
// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
$res = json_decode($this -> httpGet($url));
$ticket = $res -> ticket;
if ($ticket) {
$data -> expire_time = time() + 7000;
$data -> jsapi_ticket = $ticket;
$fp = fopen("jsapi_ticket.json", "w");
fwrite($fp, json_encode($data));
fclose($fp);
}
} else {
$ticket = $data -> jsapi_ticket;
}

return $ticket;
}

private function getAccessToken() {
// access_token 应该全局存储与更新,以下代码以写入到文件中做示例
$data = json_decode(file_get_contents("access_token.json"));
if ($data -> expire_time < time()) {
// 如果是企业号用以下URL获取access_token
// $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
$res = json_decode($this -> httpGet($url));
$access_token = $res -> access_token;
if ($access_token) {
$data -> expire_time = time() + 7000;
$data -> access_token = $access_token;
$fp = fopen("access_token.json", "w");
fwrite($fp, json_encode($data));
fclose($fp);
}
}else{
$access_token = $data -> access_token;
}
return $access_token;
}

private function httpGet($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
}


 
在jsjdk.php 同级目录创建两个文件,分别是 access_token.json 和 jsapi_ticket.json
 
修改配置信息,使用微信访问就可以正常分享了

index.php

<?php
require_once "jssdk.php";
$jssdk = new JSSDK("开发者ID", "开发者密码");//在微信开发 基本配置里面找到填写
$signPackage = $jssdk->GetSignPackage();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
wx.config({
debug: false,
appId: '<?php echo $signPackage["appId"];?>',
timestamp: <?php echo $signPackage["timestamp"];?>,
nonceStr: '<?php echo $signPackage["nonceStr"];?>',
signature: '<?php echo $signPackage["signature"];?>',
jsApiList: [ //要用的接口必须在这里注册
'onMenuShareTimeline'
]
});
wx.ready(function () {
wx.onMenuShareTimeline({
title: '我是分享显示在微信里边的标题喔', // 分享标题
link: 'http://www.shili.com/arc/65124.html', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: 'http://img.shili.com/2018/u56841254/share.jpg', // 分享图标
success: function () {
//用户点击了分享后执行的回调函数
}
});

//更多分享接口就不在多写了,详情请查阅 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
});
</script>
</html>
不明白的可以下边留言喔
一款跨平台的通讯工具。支持单人、多人参与。通过手机网络发送语音、图片、视频和文字。