方法1:
<?php
$api_code = "小程序的唯一API码";
$desp="发送内容(自行编写)";
file_get_contents('https://www.lmcjl.com/wechat/api?api_code='.$api_code.'&text='.$desp);
?>
方法2:
<?php
function http_post($url,$param,$post_file=false){
$oCurl = curl_init();
if(stripos($url,"https://")!==FALSE){
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
if (is_string($param) || $post_file) {
$strPOST = $param;
} else {
$aPOST = array();
foreach($param as $key=>$val){
$aPOST[] = $key."=".urlencode($val);
}
$strPOST = join("&", $aPOST);
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($oCurl, CURLOPT_POST,true);
curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if(intval($aStatus["http_code"])==200){
return $sContent;
}else{
return false;
}
}
$api_code = "小程序的唯一API码";
$desp="发送内容(自行编写)";
http_post('https://www.lmcjl.com/wechat/api','api_code='.$api_code.'&text='.$desp);
?>
方法3:
function http_get($url) {
$oCurl = curl_init();
if (stripos($url, "https://") !== FALSE) {
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if (intval($aStatus["http_code"]) == 200) {
return $sContent;
} else {
return false;
}
}
$api_code = "小程序的唯一API码";
$desp="发送内容(自行编写)";
http_get('https://www.lmcjl.com/wechat/api?api_code='.$api_code.'&text='.$desp);
其他用法(可get可post):
只需把api_code码和发送内容text的参数拼接链接
https://www.lmcjl.com/wechat/api
通过get或post即可
最终链接:https://www.lmcjl.com/wechat/api?api_code=api_code&text=内容
建议用方法二和三的curl。不建议用方法一file_get_contents
但是,最终还是自行选择。
功能补充:
需要储存发送数据,后缀新增status
status 默认0 1为储存 可在网站API接口的消息通知的历史数据里面查询
也可在小程序左上角的新消息按钮查询,小程序查询只能查询当日的历史记录
最终链接:
https://www.lmcjl.com/wechat/api?api_code=api_code&text=内容&status=1
返回数据json格式:{"result":"\u53d1\u9001\u6210\u529f","success":1}success状态:0为条件不符合(条件不符提示会在result字段返回) 1为发送成功 2为没有能量了(即发送失败,需要前往小程序补充能量)result为:返回提示信息