Weiphp后台群发推送微信公众号文章插件【基础/单篇推送】
发布时间:2017-11-02, 15:05:22 分类:PHP | 编辑 off 网址 | 辅助
图集1/7
正文 3413字数 2,022,809阅读
安装插件
在后台安装插件

在后台安装插件
添加模型字段

模型标识
模型名称
列表定义
字段

模型标识
qunsend
Run code
Cut to clipboard
模型名称
群发推送
Run code
Cut to clipboard
列表定义
id:ID
title:标题
ctime|time_format:预览时间
qf:当前
id|get_name_by_status_qunfasyl:群发预览
id|get_name_by_status_qunfas:群发推送
Run code
Cut to clipboard
字段
字段 | 名称 | 数据类型 | 是否显示 | 是否必填 |
---|---|---|---|---|
coverurl | 封面图片url | 字符串 | 不显示 | 否 |
content | 图文消息页面的内容 | 编辑器 | 不显示 | 否 |
sid | 推送文章id | 数字 | 不显示 | 否 |
media_id | media_id | 字符串 | 不显示 | 否 |
title | 标题 | 字符串 | 始终显示 | 否 |
ctime | 时间 | 时间 | 始终显示 | 否 |
qf | 状态 | 字符串 | 始终显示 | 否 |
图文回复
列表定义 添加
列表定义 添加
id|get_name_by_status_scqf:推送群发
Run code
Cut to clipboard
添加全局函数
\Application\Common\Common\function.php
Run code
Cut to clipboard
//start
// 以POST方式提交数据
function post_data($url, $param, $is_file = false, $return_array = true) {
if (! $is_file && is_array ( $param )) {
$param = JSON ( $param );
}
if ($is_file) {
$header [] = "content-type: multipart/form-data; charset=UTF-8";
} else {
$header [] = "content-type: application/json; charset=UTF-8";
}
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)' );
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $param );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
$res = curl_exec ( $ch );
$flat = curl_errno ( $ch );
if ($flat) {
$data = curl_error ( $ch );
addWeixinLog ( $flat, 'post_data flat' );
addWeixinLog ( $data, 'post_data msg' );
}
curl_close ( $ch );
$return_array && $res = json_decode ( $res, true );
return $res;
}
//生成群发文章
function get_name_by_status_scqf($val){
return '<a href="/index.php?s=/addon/Qunsend/Qunsend/sf/id/'.$val.'">生成</a>';
}
//群发推送
function get_name_by_status_qunfas($val, $name, $model_id) {
//$newwwtt=date('YmdH',time());
//$mm=md5('iswtf.com99'.$val.$newwwtt); /mm/'.$mm.'
return '<a href="/index.php?s=/addon/Qunsend/Qunsend/qunfas/id/'.$val.'">推送</a>';
}
//群发预览
function get_name_by_status_qunfasyl($val, $name, $model_id) {
//$newwwtt=date('YmdH',time());
//$mm=md5('iswtf.com99'.$val.$newwwtt); /mm/'.$mm.'
return '<a href="/index.php?s=/addon/Qunsend/Qunsend/qunfasyl/id/'.$val.'">预览 </a>';
}
//end
Run code
Cut to clipboard
微网站设置
添加设置配置修改文件
添加设置配置修改文件
\Addons\WeiSite\config.php
Run code
Cut to clipboard
,
'bbyueyuesjttsyywxh' => array (
'title' => '群发推送管理员预览微信号:',
'type' => 'text',
'value' => '',
'tip' => ''
),
'wxfmzdddd'=>array(
'title'=>'群发推送文图片封面:',
'type'=>'radio', //表单的类型:text、textarea、checkbox、radio、select等
'options'=>array( //select 和radion、checkbox的子选项
'1'=>'完整显示(上下/左右有空白)', //值=>文字
'0'=>'默认拉伸剪切(图片显示不完全)',
),
'value'=>'0', //表单的默认值
'tip'=>'建议尺寸900x500'
)
Run code
Cut to clipboard
在网站根目录放置图片
没有封面图片时默认显示此图片
完整显示封面模式背景图片(右键保存↓图片)

↑保存文件名
新合成封面图片将保存在网站根目录 12345678980.jpg 再上传至微信服务器
weiphp微信多客服系统插件
没有封面图片时默认显示此图片
logo.png
Run code
Cut to clipboard
完整显示封面模式背景图片(右键保存↓图片)
↑保存文件名
a.png
Run code
Cut to clipboard
新合成封面图片将保存在网站根目录 12345678980.jpg 再上传至微信服务器
weiphp微信多客服系统插件
(支付宝)给作者钱财以资鼓励 (微信)→
有过 14 条评论 »
需要发送一个 http Content-Type头信息,即 “Content-Type: application/json; charset=utf-8”
<?php /** * PHP发送Json对象数据 * * @param $url 请求url * @param $jsonStr 发送的json字符串 * @return array */ function http_post_json($url, $jsonStr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($jsonStr) ) ); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return array($httpCode, $response); } $url = "http://52php.cnblogs.com"; $jsonStr = json_encode(array('a' => 1, 'b' => 2, 'c' => 2)); list($returnCode, $returnContent) = http_post_json($url, $jsonStr);
图像打标API调用
场景识别API调用
请求参数,以json格式放置于Https Body内
<?php $akId = "*************"; $akSecret = "******************"; //更新api信息 $url = "https://shujuapi.aliyun.com/org_code/service_code/api_name?param1=xxx¶m2=xxx"; $options = array( 'http' => array( 'header' => array( 'accept'=> "application/json", 'content-type'=> "application/json", 'date'=> gmdate("D, d M Y H:i:s \G\M\T"), 'authorization' => '' ), 'method' => "GET", //可以是 GET, POST, DELETE, PUT 'content' => '' //如有数据,请用json_encode()进行编码 ) ); $http = $options['http']; $header = $http['header']; $urlObj = parse_url($url); if(empty($urlObj["query"])) $path = $urlObj["path"]; else $path = $urlObj["path"]."?".$urlObj["query"]; $body = $http['content']; if(empty($body)) $bodymd5 = $body; else $bodymd5 = base64_encode(md5($body,true)); $stringToSign = $http['method']."\n".$header['accept']."\n".$bodymd5."\n".$header['content-type']."\n".$header['date']."\n".$path; $signature = base64_encode( hash_hmac( "sha1", $stringToSign, $akSecret, true)); $authHeader = "Dataplus "."$akId".":"."$signature"; $options['http']['header']['authorization'] = $authHeader; $options['http']['header'] = implode( array_map( function($key, $val){ return $key.":".$val."\r\n"; }, array_keys($options['http']['header']), $options['http']['header'])); $context = stream_context_create($options); $file = file_get_contents($url, false, $context ); echo($file);
$json3=json_encode($jsonArr,JSON_UNESCAPED_UNICODE); $res=json_decode($res,true);
mixed json_decode ( string $json [, bool $assoc ] ) assoc 当该参数为 TRUE 时,将返回 array 而非 object 。 string json_encode ( mixed $value [, int $options = 0 ] ) 返回 value 值的 JSON 形式 Report a bug 参数 value 待编码的 value ,除了resource 类型之外,可以为任何数据类型 该函数只能接受 UTF-8 编码的数据 options 由以下常量组成的二进制掩码: JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_UNESCAPED_UNICODE. Report a bug 返回值 编码成功则返回一个以 JSON 形式表示的 string 或者在失败时返回 FALSE 。
//视频 2017.12.07 $s['content']=str_ireplace('#iframesrc#','<iframe src="',$s['content']); $s['content']=str_ireplace('#/iframesrc#','" width="100%" height="300" scrolling="no" frameborder="0"></iframe>',$s['content']); $content=$s['content'];
<p>#iframesrc#https://v.qq.com/iframe/player.html?vid=l0515xe3dfr&tiny=0&auto=0#/iframesrc##iframesrc#https://v.qq.com/iframe/player.html?vid=f05153v0sdp&tiny=0&auto=0#/iframesrc#</p>
<?php //获取access_token $appid = "wxff7c********"; $appsecret = "197*******7a*******5"; function access_token($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); // 对认证证书来源的检查,FALSE表示阻止对证书的合法性的检查。 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//将使用PHP curl获取页面内容或提交数据,作为变量储存,而不是直接输出。 $output = curl_exec($ch);// 执行操作,这里就是返回的结果 $jsoninfo = json_decode($output, true); $access_token = $jsoninfo["access_token"]; curl_close($ch);//关闭一个curl会话 //echo $access_token;exit; return $access_token; } //print_r($post);exit; //post请求 function post($url,$post) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查,FALSE表示阻止对证书的合法性的检查。 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_POST , 1); //使用post提交数据 curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //设置 post提交的数据 //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $jsoninfo = json_decode($output, true); return $output; } function get($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查,FALSE表示阻止对证书的合法性的检查。 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//将使用PHP curl获取页面内容或提交数据,作为变量储存,而不是直接输出。 $response = curl_exec($ch); // 已经获取到内容,没有输出到页面上。 $jsoninfo = json_decode($response, true); return $jsoninfo; } //自定义菜单 function menudiy($appid,$appsecret){ $access_token=access_token($appid,$appsecret); $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$access_token}"; $post='{ "button":[ { "type":"view", "name":"微官网", "url":"http://www.liangtianmei.com/index.php?s=/addon/WeiSite/WeiSite/index.html" }, { "name":"网页授权", "sub_button":[ { "type":"view", "name":"base型", "url":"http://www.liangtianmei.com/menu.php" }, { "type":"view", "name":"userinfo型", "url":"http://www.liangtianmei.com/menu.php" } ] }] }'; post($url,$post); } function snsapi_base($appid,$appsecret,$redirect_url){ $snsapi_base_url="https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$redirect_url}&response_type=code&scope=snsapi_base&state=123#wechat_redirect"; if(!isset($_GET['code'])){ header("Location:{$snsapi_base_url}"); } $code=$_GET['code']; $url="https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code"; get($url); } function snsapi_userinfo($appid,$appsecret,$redirect_url){ $snsapi_userinfo_url="https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri={$redirect_url}&response_type=code&scope=snsapi_userinfo&state=1443#wechat_redirect"; if(!isset($_GET['code'])){ header("Location:{$snsapi_userinfo_url}"); } $code=$_GET['code']; //return $code;exit; //return $appid;exit; $urlll="https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code"; $rrr= get($urlll); $access_token=$rrr['access_token']; $openid=$rrr['openid']; //return $access_token;exit; $urls="https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN"; return get($urls); //return get($urls); } //echo snsapi_userinfo(); ?>
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查,FALSE表示阻止对证书的合法性的检查。 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
微信请在菜单中选择在浏览器中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>微信弹出遮罩</title> </head> <body> <style type="text/css"> *{margin:0; padding:0;} img{max-width: 100%; height: auto;} .test{height: 600px; max-width: 600px; font-size: 40px;} </style> <div class="test"> <a href="http://mp.weixin.qq.com/mp/redirect?url=http://mobile.xinlianwang.com/android/distributor/DistributorApp.apk#weixin.qq.com#wechat_redirect ">有效跳转</a> </div> <script type="text/javascript"> function is_weixin() { var ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "micromessenger") { return true; } else { return false; } } var isWeixin = is_weixin(); var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight; function loadHtml(){ var div = document.createElement('div'); div.id = 'weixin-tip'; div.innerHTML = '<p><img src="live_weixin.png" alt="微信打开"/></p>'; document.body.appendChild(div); } function loadStyleText(cssText) { var style = document.createElement('style'); style.rel = 'stylesheet'; style.type = 'text/css'; try { style.appendChild(document.createTextNode(cssText)); } catch (e) { style.styleSheet.cssText = cssText; //ie9以下 } var head=document.getElementsByTagName("head")[0]; //head标签之间加上style样式 head.appendChild(style); } var cssText = "#weixin-tip{position: fixed; left:0; top:0; background: rgba(0,0,0,0.8); filter:alpha(opacity=80); width: 100%; height:100%; z-index: 100;} #weixin-tip p{text-align: center; margin-top: 10%; padding:0 5%;}"; if(isWeixin){ loadHtml(); loadStyleText(cssText); } </script> </body> </html>