first commit
This commit is contained in:
Executable
+695
@@ -0,0 +1,695 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xuxb
|
||||
* Date: 2019/7/25
|
||||
* Time: 16:40
|
||||
*/
|
||||
class Hdwechat
|
||||
{
|
||||
private $log_file = "wechat.log";
|
||||
private $log_dir;
|
||||
|
||||
public $appid = '';
|
||||
public $secret = '';
|
||||
public $token_url = '';//第三方地址获取token
|
||||
private $access_token = '';
|
||||
private $hd_wechat;
|
||||
|
||||
|
||||
/**
|
||||
* Hdwechat constructor.
|
||||
* @param array $config {'appid':'', 'secret':'', 'token_url':'第三方方式获取token'}
|
||||
*/
|
||||
function __construct($config = array())
|
||||
{
|
||||
$config && $this->init($config);
|
||||
$class_name = get_class($this);
|
||||
$this->log_file = "{$class_name}_{$this->appid}.log";
|
||||
$this->log_dir = "{$class_name}_{$this->appid}";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config ('appid', 'secret')
|
||||
*/
|
||||
function init($config)
|
||||
{
|
||||
$this->appid = $config['appid'];
|
||||
$this->secret = $config['secret'];
|
||||
$this->token_url = $config['token_url'];
|
||||
|
||||
$CI = &get_instance();
|
||||
$CI->load->library("hd_wechat", $config);
|
||||
/*这里用new的方式,因为load如果对象已经存在,会去取旧的,不会生成新配置的对象*/
|
||||
$this->hd_wechat = new Hd_wechat($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取或者重置access_token
|
||||
* @param $reset (是否重置)
|
||||
* @return mixed
|
||||
*/
|
||||
function access_token($reset = false)
|
||||
{
|
||||
$this->access_token = $this->hd_wechat->access_token($reset);
|
||||
|
||||
return $this->access_token;
|
||||
}
|
||||
|
||||
function activityid($unionid)
|
||||
{
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
$pre_url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/activityid/create?unionid={$unionid}&access_token=";
|
||||
$url = $pre_url . $access_token;
|
||||
$res = $this->url_get($url);
|
||||
$ret = json_decode($res, true);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成二维码
|
||||
* @param $filename (文件名称)
|
||||
* @param $scene (最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
|
||||
* @param $page (必须是已经发布的小程序存在的页面(否则报错),例如 pages/index/index, 根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面)
|
||||
* @param $width (二维码的宽度,单位 px,最小 280px,最大 1280px,默认430px)
|
||||
* @return array {'file':'文件路径', 'url':'访问相对路径'}
|
||||
*/
|
||||
function qrcode($filename, $scene, $page, $width)
|
||||
{
|
||||
$file = APPPATH . '../www/api/wx/' . $filename . '.png';
|
||||
$dir = substr($file, 0, strrpos($file, '/'));
|
||||
if (!is_dir($dir)) {
|
||||
$ret = mkdir($dir, 0777, true);// 如果文件夹不存在,将以递归方式创建该文件夹
|
||||
if (!$ret) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": mkdir {$ret}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($file)) {
|
||||
return array('file' => $file, 'url' => 'wx/' . $filename . '.png');
|
||||
}
|
||||
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$pre_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
||||
$url = $pre_url . $access_token;
|
||||
$data = array(
|
||||
'scene' => $scene,
|
||||
'page' => $page,
|
||||
'width' => $width ? $width : 430,
|
||||
);
|
||||
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if (isset($ret['errcode']) && 40001 == $ret['errcode']) {//token过期,重置后请求
|
||||
$url = $pre_url . $this->access_token(true);
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if (isset($ret['errcode'])) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": httpcode:{$code}, response:{$res}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$ret = file_put_contents($file, $res);
|
||||
if (false === $ret) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": file_put_contents {$ret}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
return array('file' => $file, 'url' => 'wx/' . $filename . '.png');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信用户信息
|
||||
* @param $openid
|
||||
* @return array|mixed
|
||||
*/
|
||||
function user($openid)
|
||||
{
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$pre_url = "https://api.weixin.qq.com/cgi-bin/user/info?openid={$openid}&lang=zh_CN&access_token=";
|
||||
$url = $pre_url . $access_token;
|
||||
$res = $this->url_get($url);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if (isset($ret['errcode']) && 40001 == $ret['errcode']) {//token过期,重置后请求
|
||||
$url = $pre_url . $this->access_token(true);
|
||||
$res = $this->url_get($url);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if (isset($ret['errcode'])) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":url=$url, res={$res}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"subscribe": 1,//是否关注
|
||||
"openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M",
|
||||
"nickname": "Band",
|
||||
"sex": 1,
|
||||
"language": "zh_CN",
|
||||
"city": "广州",
|
||||
"province": "广东",
|
||||
"country": "中国",
|
||||
"headimgurl":"http://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
|
||||
"subscribe_time": 1382694957,
|
||||
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"
|
||||
"remark": "",
|
||||
"groupid": 0,
|
||||
"tagid_list":[128,2],
|
||||
"subscribe_scene": "ADD_SCENE_QR_CODE",
|
||||
"qr_scene": 98765,
|
||||
"qr_scene_str": ""
|
||||
}
|
||||
*/
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批获取用户信息
|
||||
* @param $openids
|
||||
* @return array|mixed
|
||||
*/
|
||||
function users($openids)
|
||||
{
|
||||
$lists = array();
|
||||
foreach ($openids as $openid) {
|
||||
$lists[] = array(
|
||||
"openid" => $openid,
|
||||
'lang' => "zh_CN",
|
||||
);
|
||||
}
|
||||
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$pre_url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=";
|
||||
$url = $pre_url . $access_token;
|
||||
$data = array('user_list' => $lists);
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
if (isset($ret['errcode']) && 40001 == $ret['errcode']) {//token过期,重置后请求
|
||||
$url = $pre_url . $this->access_token(true);
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
|
||||
if (isset($ret['errcode'])) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":url=$url, res={$res}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"user_info_list": [
|
||||
{
|
||||
"subscribe": 1,
|
||||
"openid": "otvxTs4dckWG7imySrJd6jSi0CWE",
|
||||
"nickname": "iWithery",
|
||||
"sex": 1,
|
||||
"language": "zh_CN",
|
||||
"city": "揭阳",
|
||||
"province": "广东",
|
||||
"country": "中国",
|
||||
|
||||
"headimgurl": "http://thirdwx.qlogo.cn/mmopen/xbIQx1GRqdvyqkMMhEaGOX802l1CyqMJNgUzKP8MeAeHFicRDSnZH7FY4XB7p8XHXIf6uJA2SCunTPicGKezDC4saKISzRj3nz/0",
|
||||
|
||||
"subscribe_time": 1434093047,
|
||||
"unionid": "oR5GjjgEhCMJFyzaVZdrxZ2zRRF4",
|
||||
"remark": "",
|
||||
|
||||
"groupid": 0,
|
||||
"tagid_list":[128,2],
|
||||
"subscribe_scene": "ADD_SCENE_QR_CODE",
|
||||
"qr_scene": 98765,
|
||||
"qr_scene_str": ""
|
||||
|
||||
},
|
||||
{
|
||||
"subscribe": 0,
|
||||
"openid": "otvxTs_JZ6SEiP0imdhpi50fuSZg"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
* */
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @param $next_openid (起始openid,默认从头开始)
|
||||
* @return array {'total':'总数', 'count':'这次获取数', 'data':{'openid'['openid'],'next_openid':'下一页起始openid'}}
|
||||
*/
|
||||
function openids($next_openid = '')
|
||||
{
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$pre_url = "https://api.weixin.qq.com/cgi-bin/user/get?next_openid={$next_openid}&access_token=";
|
||||
$url = $pre_url . $access_token;
|
||||
$res = $this->url_get($url);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if (isset($ret['errcode']) && 40001 == $ret['errcode']) {//token过期,重置后请求
|
||||
$url = $pre_url . $this->access_token(true);
|
||||
$res = $this->url_get($url);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if (isset($ret['errcode'])) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":url=$url, res={$res}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"total":2,
|
||||
"count":2,
|
||||
"data":{
|
||||
"openid":["OPENID1","OPENID2"]},
|
||||
"next_openid":"NEXT_OPENID"
|
||||
}
|
||||
*/
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取回放源视频和获取直播房间列表 共用(调用限额 10 万次/天,200 次/分钟)
|
||||
* @param $start 起始拉取房间,start = 0 表示从第 1 个房间开始拉取
|
||||
* @param $limit 每次拉取的个数上限,不要设置过大,建议 100 以内
|
||||
* @param $room_id 直播间id,当传直播间id获取视频
|
||||
*/
|
||||
function getliveinfo($start = 0, $limit = 20, $room_id = '')
|
||||
{
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'start' => $start,
|
||||
'limit' => $limit
|
||||
);
|
||||
if ($room_id) {//直播间id
|
||||
$data['room_id'] = $room_id;
|
||||
$data['action'] = 'get_replay';
|
||||
}
|
||||
$pre_url = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=";
|
||||
$url = $pre_url . $access_token;
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
if (isset($ret['errcode']) && $ret['errcode'] != 'ok') {
|
||||
debug_log("[error] " . __FUNCTION__ . ":url=$url, res={$res}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
*/
|
||||
function tag_get()
|
||||
{
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$pre_url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=";
|
||||
$url = $pre_url . $access_token;
|
||||
$res = $this->url_get($url);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if (isset($ret['errcode']) && (40001 == $ret['errcode'] || -1 == $ret['errcode'])) {//token过期,重置后请求
|
||||
$url = $pre_url . $this->access_token(true);
|
||||
$res = $this->url_get($url);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if (isset($ret['errcode'])) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":url=$url, res={$res}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"tags":[{
|
||||
"id":1,
|
||||
"name":"每天一罐可乐星人",
|
||||
"count":0 //此标签下粉丝数
|
||||
}]
|
||||
}
|
||||
*/
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tagid
|
||||
* @param string $next_openid
|
||||
* @return array|mixed
|
||||
*/
|
||||
function tag_user($tagid, $next_openid = '')
|
||||
{
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$pre_url = "https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=";
|
||||
$url = $pre_url . $access_token;
|
||||
|
||||
$data = array(
|
||||
'tagid' => $tagid,
|
||||
'next_openid' => $next_openid,
|
||||
);
|
||||
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if (isset($ret['errcode']) && (40001 == $ret['errcode'] || -1 == $ret['errcode'])) {//token过期,重置后请求
|
||||
$url = $pre_url . $this->access_token(true);
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if (isset($ret['errcode'])) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":url=$url, res={$res}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"count":2,//这次获取的粉丝数量
|
||||
"data":{//粉丝列表
|
||||
"openid":[
|
||||
"ocYxcuAEy30bX0NXmGn4ypqx3tI0",
|
||||
"ocYxcuBt0mRugKZ7tGAHPnUaOW7Y" ]
|
||||
},
|
||||
"next_openid":"ocYxcuBt0mRugKZ7tGAHPnUaOW7Y"//拉取列表最后一个用户的openid
|
||||
}
|
||||
*/
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容安全校验
|
||||
* @param $type "msg内容, img图片"
|
||||
* @param $data
|
||||
* @return array|mixed
|
||||
*/
|
||||
function sec_check($type, $data)
|
||||
{
|
||||
$pre_url = "https://api.weixin.qq.com/wxa/servicemarket?access_token=";
|
||||
$post_data = array();
|
||||
switch ($type) {
|
||||
case 'msg':
|
||||
$post_data = array(
|
||||
"service" => "wxee446d7507c68b11",
|
||||
'api' => "msgSecCheck",
|
||||
"client_msg_id" => "client_msg_id_1",
|
||||
"data" => array(
|
||||
"Action" => "TextApproval",
|
||||
"Text" => $data,
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 'img':
|
||||
$post_data = array(
|
||||
"service" => "wxee446d7507c68b11",
|
||||
'api' => "msgSecCheck",
|
||||
"client_msg_id" => "client_msg_id_1",
|
||||
"data" => array(
|
||||
"Action" => "ImageModeration",
|
||||
"Scenes" => ["PORN", "POLITICS", "TERRORISM"],
|
||||
"ImageUrl" => $data,
|
||||
"ImageBase64" => "",
|
||||
"Config" => "",
|
||||
"Extra" => ""
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$post_data) {
|
||||
debug_log("[error]# " . __FUNCTION__ . ": unknow type:{$type}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$access_token = $this->access_token();
|
||||
if (!$access_token) {
|
||||
debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
$url = $pre_url . $access_token;
|
||||
|
||||
list($code, $res) = $this->curl_post($url, $post_data);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if (isset($ret['errcode']) && 40001 == $ret['errcode']) {//token过期,重置后请求
|
||||
$url = $pre_url . $this->access_token(true);
|
||||
list($code, $res) = $this->curl_post($url, $post_data);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if (0 != $ret['errcode'] && 80714) {
|
||||
debug_log("[error] " . __FUNCTION__ . ":url=$url, res={$res}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case "msg":
|
||||
/*
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "ok",
|
||||
"data": "{$data}",
|
||||
"request_id": "MLw1pg8TN_O8SFol2BwbHNsKJtGl_Vf7WEaBObyDjYifxq9hx8v-TpQne9X_1jilYwA",
|
||||
"provider_errmsg": "",
|
||||
}
|
||||
$data={
|
||||
"Response": {
|
||||
"EvilTokens": [
|
||||
{
|
||||
"EvilFlag": 1,
|
||||
"EvilType": 2,
|
||||
"EvilKeywords": [
|
||||
"骚逼"
|
||||
]
|
||||
},
|
||||
{
|
||||
"EvilFlag": 1,
|
||||
"EvilType": 3,
|
||||
"EvilKeywords": [
|
||||
"你妈逼",
|
||||
"我草",
|
||||
"王八蛋",
|
||||
"你他妈的"
|
||||
]
|
||||
},
|
||||
{
|
||||
"EvilFlag": 2,
|
||||
"EvilType": 3,
|
||||
"EvilKeywords": [
|
||||
"他妈的",
|
||||
"你他妈",
|
||||
"骚逼",
|
||||
"我草你妈",
|
||||
"王八"
|
||||
]
|
||||
}
|
||||
],
|
||||
"RequestId": "2cb93e69-8f5a-47a3-8dc3-93f177f2912b"
|
||||
}
|
||||
}
|
||||
*/
|
||||
$EvilFlags = array("正常", "恶意", "可疑送审");
|
||||
$EvilTypes = array(
|
||||
0 => '正常',
|
||||
1 => '政治',
|
||||
2 => '色情',
|
||||
3 => '辱骂/低俗',
|
||||
4 => '暴恐/毒品',
|
||||
5 => '广告/灌水',
|
||||
6 => '迷信/邪教',
|
||||
7 => '其他违法(如跨站追杀/恶意竞争等)',
|
||||
8 => '综合',
|
||||
9 => '联系方式/链接',
|
||||
);
|
||||
$msg = "";
|
||||
if (0 == $ret['errcode'] && $ret['data']) {
|
||||
$response = json_decode($ret['data'], true);
|
||||
if ($response['Response'] && $response['Response']['EvilTokens']) {
|
||||
$rows = $response['Response']['EvilTokens'];
|
||||
foreach ($rows as $v) {
|
||||
$msg .= "{$EvilFlags[$v['EvilFlag']]}-{$EvilTypes[$v['EvilType']]}:" . implode(',', $v['EvilKeywords']) . ";";
|
||||
}
|
||||
}
|
||||
$ret['msg'] = $msg;
|
||||
}
|
||||
break;
|
||||
case "img":
|
||||
/* 图片审核返回值
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "ok",
|
||||
"data": "{$data}",
|
||||
"request_id": "MLxQcr8W8oGH0nrM7d0FNjYtWap5v-FIjCVDH0zVV9oprnDyD2sKCiBPl7iT8zWEWPw",
|
||||
"provider_errmsg": "",
|
||||
}
|
||||
$data={
|
||||
"Response": {
|
||||
"PornResult": {
|
||||
"Suggestion": "BLOCK",
|
||||
"Confidence": 99,
|
||||
"AdvancedInfo": "",
|
||||
"Type": "PORN",
|
||||
"Code": 0,
|
||||
"Msg": "OK"
|
||||
},
|
||||
"PoliticsResult": {
|
||||
"Suggestion": "PASS",
|
||||
"Confidence": 37,
|
||||
"AdvancedInfo": "",
|
||||
"Type": "DNA",
|
||||
"Code": 0,
|
||||
"Msg": "OK",
|
||||
"FaceResults": []
|
||||
},
|
||||
"TerrorismResult": {
|
||||
"Suggestion": "PASS",
|
||||
"Confidence": 0,
|
||||
"AdvancedInfo": "",
|
||||
"Type": "LABEL",
|
||||
"Code": 0,
|
||||
"Msg": "OK",
|
||||
"FaceResults": []
|
||||
},
|
||||
"DisgustResult": null,
|
||||
"TextResult": null,
|
||||
"Suggestion": "BLOCK",
|
||||
"Extra": "",
|
||||
"RequestId": "33b73a27-8bb6-48d6-855e-cb6bab2faf20"
|
||||
}
|
||||
}
|
||||
*/
|
||||
$sugs = array("pass" => "正常", 'review' => "疑似", "block" => "违规");
|
||||
$types = array(
|
||||
"PornResult" => "色情",
|
||||
"TerrorismResult" => "暴恐",
|
||||
"PoliticsResult" => "政治敏感",
|
||||
"DisgustResult" => "恶心内容",
|
||||
"TextResult" => "文字",
|
||||
);
|
||||
$msg = "";
|
||||
if (0 == $ret['errcode'] && $ret['data']) {
|
||||
$response = json_decode($ret['data'], true);
|
||||
if ($response['Response']) {
|
||||
foreach ($response['Response'] as $k => $type) {
|
||||
if (!$types[$k] || !$type) {
|
||||
continue;
|
||||
}
|
||||
$sug = strtolower($type['Suggestion']);
|
||||
if ('pass' == $sug) {
|
||||
continue;
|
||||
}
|
||||
$msg .= "{$types[$k]}:{$sugs[$sug]};";
|
||||
}
|
||||
}
|
||||
$ret['msg'] = $msg;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从其他接口获取token,保证获取token不影响其他平台
|
||||
* @param $url
|
||||
* @return string
|
||||
*/
|
||||
private function get_self_token($url)
|
||||
{
|
||||
$res = trim(file_get_contents($url));
|
||||
|
||||
debug_log("[info] " . __FUNCTION__ . ":url={$url}, res={$res}", $this->log_file);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
private function curl_post($url, $data)
|
||||
{
|
||||
debug_log("[info] " . __FUNCTION__ . ":url={$url}, data=" . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_file);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
$res = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
$size = strlen($res);
|
||||
if ($size > 5000) {
|
||||
debug_log("[info] " . __FUNCTION__ . ":httpcode={$code}, response is big only show size={$size}", $this->log_file);
|
||||
} else {
|
||||
debug_log("[info] " . __FUNCTION__ . ":httpcode={$code}, response={$res}", $this->log_file);
|
||||
}
|
||||
|
||||
return array($code, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @return string
|
||||
*/
|
||||
private function url_get($url)
|
||||
{
|
||||
$res = file_get_contents($url);
|
||||
debug_log("[info] " . __FUNCTION__ . ":url={$url}, res={$res}", $this->log_file);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Executable
+226
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xuxb
|
||||
* Date: 2019/7/25
|
||||
* Time: 16:40
|
||||
*/
|
||||
class Hdwechat1{
|
||||
private $log_file = "wechat.log";
|
||||
|
||||
public $appid = '';
|
||||
public $secret = '';
|
||||
public $token_url = '';//第三方地址获取token
|
||||
private $access_token = '';
|
||||
|
||||
|
||||
/**
|
||||
* Hdwechat constructor.
|
||||
* @param array $config {'appid':'', 'secret':'', 'token_url':'第三方方式获取token'}
|
||||
*/
|
||||
function __construct($config = array()){
|
||||
$config && $this->init($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config ('appid', 'secret')
|
||||
*/
|
||||
function init($config){
|
||||
$this->appid = $config['appid'];
|
||||
$this->secret = $config['secret'];
|
||||
$this->token_url = $config['token_url'];
|
||||
|
||||
$CI = & get_instance();
|
||||
$CI->load->library("hd_wechat", $config);
|
||||
$this->hd_wechat = new Hd_wechat($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取或者重置access_token
|
||||
* @param $reset (是否重置)
|
||||
* @return mixed
|
||||
*/
|
||||
function access_token($reset = false){
|
||||
$this->access_token = $this->hd_wechat->access_token($reset);
|
||||
|
||||
return $this->access_token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成二维码
|
||||
* @param $filename (文件名称)
|
||||
* @param $scene (最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
|
||||
* @param $page (必须是已经发布的小程序存在的页面(否则报错),例如 pages/index/index, 根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面)
|
||||
* @param $width (二维码的宽度,单位 px,最小 280px,最大 1280px,默认430px)
|
||||
* @return array {'file':'文件路径', 'url':'访问相对路径'}
|
||||
*/
|
||||
function wxacode($filename, $scene, $page, $width){
|
||||
$file = APPPATH . '../www/home/wx/wxacode/' . $filename . '.png';
|
||||
$dir = substr($file, 0, strrpos($file, '/'));
|
||||
if(!is_dir($dir)){
|
||||
$ret = mkdir($dir, 0777, true);// 如果文件夹不存在,将以递归方式创建该文件夹
|
||||
if(!$ret){
|
||||
debug_log("[error] ". __FUNCTION__ . ": mkdir {$ret}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
if(file_exists($file)){
|
||||
return array('file' => $file, 'url' => 'wx/wxacode/' . $filename . '.png');
|
||||
}
|
||||
|
||||
$pre_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=';
|
||||
$url = $pre_url . $this->access_token();
|
||||
$data = array(
|
||||
'scene' => $scene,
|
||||
'page' => $page,
|
||||
'width' => $width ? $width : 430,
|
||||
);
|
||||
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if(isset($ret['errcode']) && 40001 == $ret['errcode']){//token过期,重置后请求
|
||||
$url = $pre_url . $this->access_token(true);
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if(isset($ret['errcode'])){
|
||||
debug_log("[error] ". __FUNCTION__ . ": httpcode:{$code}, response:{$res}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
$ret = file_put_contents($file, $res);
|
||||
if(false === $ret){
|
||||
debug_log("[error] ". __FUNCTION__ . ": file_put_contents {$ret}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
return array('file' => $file, 'url' => 'wx/' . $filename . '.png');
|
||||
}
|
||||
|
||||
function qrcode($filename, $scene, $type = 0, $expire = 0){
|
||||
$file = APPPATH . '../www/api/wx/qrcode/' . $filename . '.png';
|
||||
$file_url = 'wx/qrcode/' . $filename . '.png';
|
||||
$dir = substr($file, 0, strrpos($file, '/'));
|
||||
if(!is_dir($dir)){
|
||||
$ret = mkdir($dir, 0777, true);// 如果文件夹不存在,将以递归方式创建该文件夹
|
||||
if(!$ret){
|
||||
debug_log("[error] ". __FUNCTION__ . ": mkdir {$ret}, filename:{$filename}, scene:{$scene}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
if(file_exists($file)){
|
||||
return array('file' => $file, 'url' => $file_url);
|
||||
}
|
||||
|
||||
if(is_numeric($scene)){
|
||||
$action_info = array(
|
||||
'scene' => array('scene_id' => $scene)
|
||||
);
|
||||
$action_name = $type ? 'QR_LIMIT_SCENE' : 'QR_SCENE';
|
||||
} else {
|
||||
$action_info = array(
|
||||
'scene' => array('scene_str' => $scene)
|
||||
);
|
||||
$action_name = $type ? 'QR_LIMIT_STR_SCENE' : 'QR_STR_SCENE';
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'action_name' => $action_name,
|
||||
'action_info' => $action_info
|
||||
);
|
||||
$expire && $data['expire_seconds'] = $expire;
|
||||
|
||||
$qr_url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=';
|
||||
$url = $qr_url . $this->access_token();
|
||||
|
||||
//请求获取二维码的ticket
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if(isset($ret['errcode']) && 40001 == $ret['errcode']){//token过期,重置后请求
|
||||
$url = $qr_url . $this->access_token(true);
|
||||
list($code, $res) = $this->curl_post($url, $data);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if(isset($ret['errcode'])){
|
||||
debug_log("[error] ". __FUNCTION__ . ": httpcode:{$code}, response:{$res}, filename:{$filename}, scene:{$scene}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
if(!$ret['ticket']){
|
||||
debug_log("[error] ". __FUNCTION__ . ": not ticket, filename:{$filename}, scene:{$scene}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
//根据ticket获取
|
||||
$ticket_url='https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.$ret['ticket'];
|
||||
|
||||
debug_log("[info] ". __FUNCTION__ . ": ticket_url=$ticket_url", $this->log_file);
|
||||
|
||||
$ret = file_put_contents($file, $this->url_get($ticket_url));
|
||||
if(false === $ret){
|
||||
debug_log("[error] ". __FUNCTION__ . ": file_put_contents {$ret}, filename:{$filename}, scene:{$scene}", $this->log_file);
|
||||
return array();
|
||||
}
|
||||
|
||||
return array('file' => $file, 'url' => $file_url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从其他接口获取token,保证获取token不影响其他平台
|
||||
* @param $url
|
||||
* @return string
|
||||
*/
|
||||
private function get_self_token($url){
|
||||
$res = trim($this->url_get($url));
|
||||
|
||||
debug_log("[info] ". __FUNCTION__ . ":url={$url}, res={$res}", $this->log_file);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
private function curl_post($url, $data){
|
||||
debug_log("[info] ". __FUNCTION__ . ":url={$url}, data=".json_encode($data), $this->log_file);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$res = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
$size = strlen($res);
|
||||
if($size > 5000){
|
||||
debug_log("[info] ". __FUNCTION__ . ":httpcode={$code}, response is big only show size={$size}", $this->log_file);
|
||||
} else {
|
||||
debug_log("[info] ". __FUNCTION__ . ":httpcode={$code}, response={$res}", $this->log_file);
|
||||
}
|
||||
|
||||
return array($code, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @return string
|
||||
*/
|
||||
private function url_get($url){
|
||||
$res = file_get_contents($url);
|
||||
debug_log("[info] ". __FUNCTION__ . ":url={$url}, res={$res}", $this->log_file);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Executable
+104
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(dirname(__FILE__)).'/third_party/PHPMailer.php');
|
||||
/**
|
||||
* 发送邮件封装类
|
||||
* Created by PhpStorm.
|
||||
* User: xuxb
|
||||
* Date: 2018/9/12
|
||||
* Time: 11:11
|
||||
*/
|
||||
class Mymailer
|
||||
{
|
||||
private $host;//地址
|
||||
private $port;//发送邮件端口号
|
||||
private $username;//登录的账号
|
||||
private $pwd;//登录的密码
|
||||
private $debug;
|
||||
private $mailer;
|
||||
private $fromname;
|
||||
|
||||
private $config = array(
|
||||
'host' => 'smtp.163.com',
|
||||
'port' => '25',
|
||||
'username' => '18350451617@163.com',
|
||||
'pwd' => 'lin2821808',
|
||||
'fromname' => '小鱼网',
|
||||
);
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$params && $this->init($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $params 未设置默认server配置mail数组第一项
|
||||
* @param boolean $debug
|
||||
*/
|
||||
public function init($params = array(), $debug = false){
|
||||
|
||||
if($params){
|
||||
$this->host = $params['host'];
|
||||
$this->port = $params['port'];
|
||||
$this->username = $params['username'];
|
||||
$this->pwd = $params['pwd'];
|
||||
$this->fromname = $params['fromname'];
|
||||
$this->debug = $debug;
|
||||
} else {
|
||||
$params = $this->config;
|
||||
$this->host = $params['host'];
|
||||
$this->port = $params['port'];
|
||||
$this->username = $params['username'];
|
||||
$this->pwd = $params['pwd'];
|
||||
$this->fromname = $params['fromname'];
|
||||
}
|
||||
|
||||
$mailer = new PHPMailer();
|
||||
/* Server Settings */
|
||||
$mailer->IsSMTP(); // 使用 SMTP 方式发送邮件
|
||||
$mailer->SMTPAuth = true; //启用SMTP认证
|
||||
$mailer->Host = $this->host; //SMTP服务器 以163邮箱为例子
|
||||
$mailer->Port = $this->port; //邮件发送端口,163的是25,设置ssl连接smtp服务器的远程服务器端口号465
|
||||
// $mailer->SMTPSecure = 'ssl';
|
||||
$mailer->SMTPDebug = $this->debug;// 是否启用smtp的debug进行调试 开发环境建议开启 生产环境注释掉即可 默认关闭debug调试模式
|
||||
/* Account Settings */
|
||||
$mailer->Username = $this->username;
|
||||
$mailer->Password = $this->pwd;
|
||||
$mailer->From = $this->username;
|
||||
/* Content Setting */
|
||||
$mailer->IsHTML(true); //支持html格式内容
|
||||
$mailer->CharSet = 'UTF-8';
|
||||
|
||||
$this->mailer = $mailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加附件
|
||||
* @param $path (文件路径
|
||||
* @param string $name (指定名称
|
||||
*/
|
||||
public function add_attachment($path, $name=''){
|
||||
$this->mailer->AddAttachment($path, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
* @param $email (接收邮件地址
|
||||
* @param $title (邮件标题
|
||||
* @param $content (邮件内容
|
||||
* @return bool
|
||||
*/
|
||||
public function send($email, $title, $content){
|
||||
$this->mailer->FromName = $this->fromname;
|
||||
$this->mailer->addAddress($email);
|
||||
$this->mailer->Subject = $title;
|
||||
$this->mailer->Body = $content;
|
||||
|
||||
return (bool)$this->mailer->send(); // 发送邮件
|
||||
}
|
||||
|
||||
public function error(){
|
||||
var_dump($this->mailer->ErrorInfo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Notes:企业付款到微信零钱
|
||||
* Created on: 2020/7/12 15:49
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Transfers
|
||||
{
|
||||
private $app_id;
|
||||
private $wx_config_file; //配制文件地址
|
||||
|
||||
public function __construct($param = array())
|
||||
{
|
||||
$this->app_id = $param['app_id'] ? $param['app_id'] : 3; //默认飞鱼
|
||||
switch ($this->app_id) {
|
||||
case 3://飞鱼
|
||||
$this->wx_config_file = 'fy_WxPay.Config.php';
|
||||
break;
|
||||
case 14://欧菲帮我美
|
||||
$this->wx_config_file = 'ofei_WxPay.Config.php';
|
||||
break;
|
||||
case 15://星盟卡
|
||||
$this->wx_config_file = 'xmcard_WxPay.Config.php';
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:企业付款到零钱
|
||||
* 接口介绍 https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
|
||||
* Created on: 2020/7/12 18:03
|
||||
* Created by: dengbw
|
||||
* @param array $param
|
||||
* @return bool|mixed|SimpleXMLElement|string
|
||||
*/
|
||||
public function sendMoney($param = array())
|
||||
{
|
||||
require_once APPPATH . "../api/third_party/WXconfig/" . $this->wx_config_file;
|
||||
$config = new WxPayConfig();
|
||||
$partner_trade_no = $param['partner_trade_no'] ? $param['partner_trade_no']
|
||||
: date('YmdHis') . rand(1000, 9999);//商户订单号
|
||||
$amount = (100) * $param['amount']; //发送的金额(分)目前发送金额不能少于1元
|
||||
$openid = $param['openid'];//发送人的 openid
|
||||
$desc = $param['desc'] ? $param['desc'] : '提现';//企业付款描述信息 (必填)
|
||||
$re_user_name = $param['re_user_name'] ? $param['re_user_name'] : '';//收款用户姓名 (选填)
|
||||
$data = array(
|
||||
'mch_appid' => $config::APPID,//商户账号appid
|
||||
'mchid' => $config::MCHID,//商户号
|
||||
'nonce_str' => $this->createNoncestr(),//随机字符串
|
||||
'partner_trade_no' => $partner_trade_no,//商户订单号
|
||||
'openid' => $openid,//用户openid
|
||||
'check_name' => 'NO_CHECK',//校验用户姓名选项,
|
||||
're_user_name' => $re_user_name,//收款用户姓名
|
||||
'amount' => $amount,//金额
|
||||
'desc' => $desc,//企业付款描述信息
|
||||
'spbill_create_ip' => $_SERVER['REMOTE_ADDR'],//Ip地址
|
||||
);
|
||||
//生成签名算法
|
||||
$secrect_key = $config::KEY;///这个就是个API密码。MD5 32位。
|
||||
$data = array_filter($data);
|
||||
ksort($data);
|
||||
$str = '';
|
||||
foreach ($data as $k => $v) {
|
||||
$str .= $k . '=' . $v . '&';
|
||||
}
|
||||
$str .= 'key=' . $secrect_key;
|
||||
$data['sign'] = md5($str);
|
||||
//生成签名算法
|
||||
$xml = $this->arraytoxml($data);
|
||||
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; //调用接口
|
||||
$res = $this->curl_post_ssl($url, $xml, $config);
|
||||
$return = $this->xmltoarray($res);
|
||||
return $return;
|
||||
print_r($return);
|
||||
//返回来的结果
|
||||
// [return_code] => SUCCESS [return_msg] => Array ( ) [mch_appid] => wxd44be6876gg73 [mchid] => 76775512 [nonce_str] => 616615516 [result_code] => SUCCESS [partner_trade_no] => 20186505080216815
|
||||
// [payment_no] => 1000018361251805057502564679 [payment_time] => 2018-05-15 15:29:50
|
||||
$responseObj = simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
echo $res = $responseObj->return_code; //SUCCESS 如果返回来SUCCESS,则发生成功,处理自己的逻辑
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* [xmltoarray xml格式转换为数组]
|
||||
* @param [type] $xml [xml]
|
||||
* @return [type] [xml 转化为array]
|
||||
*/
|
||||
public function xmltoarray($xml)
|
||||
{
|
||||
//禁止引用外部xml实体
|
||||
libxml_disable_entity_loader(true);
|
||||
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
$val = json_decode(json_encode($xmlstring), true);
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* [arraytoxml 将数组转换成xml格式(简单方法):]
|
||||
* @param [type] $data [数组]
|
||||
* @return [type] [array 转 xml]
|
||||
*/
|
||||
public function arraytoxml($data)
|
||||
{
|
||||
$str = '<xml>';
|
||||
foreach ($data as $k => $v) {
|
||||
$str .= '<' . $k . '>' . $v . '</' . $k . '>';
|
||||
}
|
||||
$str .= '</xml>';
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* [createNoncestr 生成随机字符串]
|
||||
* @param integer $length [长度]
|
||||
* @return [type] [字母大小写加数字]
|
||||
*/
|
||||
public function createNoncestr($length = 32)
|
||||
{
|
||||
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
$str = "";
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* [curl_post_ssl 发送curl_post数据]
|
||||
* @param [type] $url [发送地址]
|
||||
* @param [type] $xmldata [发送文件格式]
|
||||
* @param [type] $second [设置执行最长秒数]
|
||||
* @param [type] $aHeader [设置头部]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
function curl_post_ssl($url, $vars, $config, $second = 30, $aHeader = array())
|
||||
{
|
||||
//设置证书位置
|
||||
$sslCertPath = $config::SSLCERT_PATH;
|
||||
$sslKeyPath = $config::SSLKEY_PATH;
|
||||
$ch = curl_init();//初始化curl
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $second);//设置执行最长秒数
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||||
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 终止从服务端进行验证
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//
|
||||
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');//证书类型
|
||||
curl_setopt($ch, CURLOPT_SSLCERT, $sslCertPath);//证书位置
|
||||
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');//CURLOPT_SSLKEY中规定的私钥的加密类型
|
||||
curl_setopt($ch, CURLOPT_SSLKEY, $sslKeyPath);//证书位置
|
||||
//curl_setopt($ch, CURLOPT_CAINFO, 'PEM');
|
||||
//curl_setopt($ch, CURLOPT_CAINFO, $isdir . 'rootca.pem');
|
||||
if (count($aHeader) >= 1) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);//设置头部
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);//全部数据使用HTTP协议中的"POST"操作来发送
|
||||
$data = curl_exec($ch);//执行回话
|
||||
if ($data) {
|
||||
curl_close($ch);
|
||||
return $data;
|
||||
} else {
|
||||
$error = curl_errno($ch);
|
||||
echo "call faild, errorCode:$error\n";
|
||||
curl_close($ch);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+290
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
|
||||
include_once 'Hdwechat.php';
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xuxb
|
||||
* Date: 2019/8/8
|
||||
* Time: 10:36
|
||||
*/
|
||||
class Wechatmsg{
|
||||
|
||||
private static $max_form = 10;
|
||||
|
||||
private $wechat;
|
||||
private $temp_id = '';//模板消息id
|
||||
private $temp_appage = '';//模板消息跳转小程序页面
|
||||
private $temp_appid = '';//模板消息跳转小程序appid
|
||||
private $temp_url = '';//模板消息跳外链
|
||||
private $log_file = "wechat_msg.log";
|
||||
|
||||
/**
|
||||
* Wechatmsg constructor.
|
||||
* @param array $config {'appid':'', 'secret':'', 'token_url':'第三方方式获取token'}
|
||||
*/
|
||||
function __construct($config = array()){
|
||||
$this->wechat = new Hdwechat($config);
|
||||
$this->cf_app = $config['cf_app'];
|
||||
if($config){
|
||||
$this->log_file = "wechat_msg_{$config['appid']}.log";
|
||||
}
|
||||
}
|
||||
|
||||
function init_wechat($config){
|
||||
$this->wechat->init($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化服务号消息模板
|
||||
* @param $id (模板ID)
|
||||
* @param $appage (小程序跳转页)
|
||||
* @param $appid (小程序appid, 默认当前小程序)
|
||||
* @param $url (跳转外链)
|
||||
*/
|
||||
function init_template($id, $appage = '', $appid = '', $url = ''){
|
||||
$this->temp_id = $id;
|
||||
$this->temp_appage = $appage;
|
||||
$this->temp_appid = $appid;
|
||||
$this->temp_url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送服务号消息
|
||||
* @param $openid
|
||||
* @param $data (消息主体)
|
||||
* @return mixed
|
||||
*/
|
||||
function send_oa($openid, $data){
|
||||
$access_token = $this->wechat->access_token();
|
||||
if(!$access_token){
|
||||
debug_log("[error] ". __FUNCTION__ . ": not access_token; openid={$openid}", $this->log_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
$pre_url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=';
|
||||
$url = $pre_url . $access_token;
|
||||
$post = array(
|
||||
'touser' => $openid,
|
||||
'template_id' => $this->temp_id,
|
||||
'url' => $this->temp_url ? $this->temp_url : '',
|
||||
'data' => $data
|
||||
);
|
||||
if($this->temp_appage){
|
||||
$post['miniprogram'] =array(
|
||||
'appid' => $this->temp_appid,
|
||||
'pagepath' => $this->temp_appage
|
||||
);
|
||||
}
|
||||
|
||||
list($code, $res) = $this->curl_json($url, $post);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if(40001 == $ret['errcode']){//token过期,重置后请求
|
||||
$url = $pre_url . $this->wechat->access_token(true);
|
||||
list($code, $res) = $this->curl_json($url, $post);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if($ret['errcode'] != 0){
|
||||
debug_log("[error] ". __FUNCTION__ . ": openid={$openid}", $this->log_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送小程序消息
|
||||
* @param $openid
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
function send_app($openid, $data){
|
||||
$access_token = $this->wechat->access_token();
|
||||
if(!$access_token){
|
||||
debug_log("[error] ". __FUNCTION__ . ": not access_token; openid={$openid}", $this->log_file);
|
||||
return false;
|
||||
}
|
||||
$pre_url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=";
|
||||
$url = $pre_url.$access_token;
|
||||
|
||||
$form_id = $this->pop_formid($openid);
|
||||
if(!$form_id){
|
||||
debug_log("[error] ". __FUNCTION__ . ": not form_id; openid={$openid}", $this->log_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
$post = array(
|
||||
'touser' => $openid,
|
||||
'template_id' => $this->temp_id,
|
||||
'form_id' => $form_id,
|
||||
'page' => $this->temp_appage,
|
||||
'data' => $data
|
||||
);
|
||||
|
||||
list($code, $res) = $this->curl_json($url, $post);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if(40001 == $ret['errcode']){//token过期,重置后请求
|
||||
$url = $pre_url . $this->wechat->access_token(true);
|
||||
list($code, $res) = $this->curl_json($url, $post);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if($ret['errcode'] != 0){
|
||||
debug_log("[error] ". __FUNCTION__ . ": from_id={$form_id}, openid={$openid}", $this->log_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送小程序订阅通知
|
||||
* @param $openid
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
function send_appsub($openid, $data){
|
||||
$access_token = $this->wechat->access_token();
|
||||
if(!$access_token){
|
||||
debug_log("[error] ". __FUNCTION__ . ":not access_token; openid={$openid}", $this->log_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
$pre_url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=";
|
||||
$url = $pre_url.$access_token;
|
||||
|
||||
$post = array(
|
||||
'touser' => $openid,
|
||||
'template_id' => $this->temp_id,
|
||||
'page' => $this->temp_appage,
|
||||
'data' => $data
|
||||
);
|
||||
|
||||
list($code, $res) = $this->curl_json($url, $post);
|
||||
$ret = json_decode($res, true);
|
||||
|
||||
if(40001 == $ret['errcode']){//token过期,重置后请求
|
||||
$url = $pre_url . $this->wechat->access_token(true);
|
||||
list($code, $res) = $this->curl_json($url, $post);
|
||||
$ret = json_decode($res, true);
|
||||
}
|
||||
|
||||
if($ret['errcode'] != 0){
|
||||
debug_log("[error] ". __FUNCTION__ . ":openid={$openid}", $this->log_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集新的form_id
|
||||
* @param $openid (用户ID)
|
||||
* @param $form_id
|
||||
* @param $expire (到期时间戳)
|
||||
* @return bool
|
||||
*/
|
||||
public function push_formid($openid, $form_id, $expire = 0){
|
||||
//从redis获取
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
$key = "wechat_formid_{$this->wechat->appid}_{$openid}";
|
||||
$long = 7 * 24 * 3600;
|
||||
|
||||
!$expire && $expire = time() + $long;
|
||||
$form = array('id' => $form_id, 'expire' => $expire);
|
||||
|
||||
$ret = $redis->lPush($key, json_encode($form));
|
||||
$len = $redis->lLen($key);
|
||||
//限制redis列表长度,去掉旧的
|
||||
$ret && $len > self::$max_form && $redis->rPop($key);
|
||||
//更新redis有效期
|
||||
$redis->expire($key, $long);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取formid数量
|
||||
* @param $openid
|
||||
* @return mixed
|
||||
*/
|
||||
function count_formid($openid){
|
||||
$key = "wechat_formid_{$this->wechat->appid}_{$openid}";
|
||||
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
return $redis->lLen($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
* @param $openid
|
||||
* @return mixed
|
||||
*/
|
||||
function view_formid($openid){
|
||||
$key = "wechat_formid_{$this->wechat->appid}_{$openid}";
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
return $redis->lRange($key, 0, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出fromid
|
||||
* @param $openid
|
||||
* @return string
|
||||
*/
|
||||
public function pop_formid($openid){
|
||||
//从redis获取
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
$key = "wechat_formid_{$this->wechat->appid}_{$openid}";
|
||||
|
||||
$now = time();
|
||||
while(1) {//循环获取fromid
|
||||
$form = $redis->rPop($key);
|
||||
$form && $form = json_decode($form, true);
|
||||
if(!$form){break;}
|
||||
if($form['expire'] >= $now){
|
||||
return $form['id'];
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
private function curl_json($url, $data){
|
||||
$data = urldecode(json_encode($data));
|
||||
debug_log("[info] ". __FUNCTION__ . ":url={$url}, data={$data}", $this->log_file);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
//https
|
||||
if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
'Content-Length: ' . strlen($data)
|
||||
)
|
||||
);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
debug_log("[info] ". __FUNCTION__ . ":httpcode={$httpCode}, response={$response}", $this->log_file);
|
||||
|
||||
return array($httpCode, $response);
|
||||
}
|
||||
}
|
||||
Executable
+347
@@ -0,0 +1,347 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xuxb
|
||||
* Date: 2018/11/8
|
||||
* Time: 14:55
|
||||
*/
|
||||
|
||||
/**
|
||||
* 微信消息模板
|
||||
* Class Wetemplate
|
||||
*/
|
||||
class Wetemplate {
|
||||
const API_URL_PREFIX = 'https://api.weixin.qq.com/cgi-bin';
|
||||
const APP_MSG_URL = '/message/wxopen/template/send';
|
||||
const ACCESS_TOKEN_URL = '/token';
|
||||
|
||||
const TMPID_LOAN = 0;
|
||||
const TMPID_PAY = 1;
|
||||
const TMPID_SVR = 2;
|
||||
const TMPID_IMG_OK = 3;
|
||||
const TMPID_IMG_NO = 4;
|
||||
|
||||
public static $tmpId_arr = array(
|
||||
'75l6xGadteSzIlIkjICm5odkZCU0NS7khfy-_zJyhmM',//放款成功
|
||||
'nnvFtlCikntD7VGnctpa8LHlSeQzoFn5sTtnblXn8OA',//消费成功
|
||||
'9D7bzAT6ypQ_IwIg2dmLw3OO2lqWlXRP5Ca92b_Fluo',//扣款成功
|
||||
'Z7d082tPMEWTwOynY5nWgjtNzSHpS5S4crfE8xHI5BY',//照片审核通过
|
||||
'Z7d082tPMEWTwOynY5nWglFbxD1IlUQIdMmBgj08-Y8',//照片审核不通过
|
||||
);
|
||||
|
||||
private $ci;
|
||||
|
||||
private $app;//应用
|
||||
|
||||
private $we_appid;
|
||||
private $we_appsecret;
|
||||
private $we_access_token;
|
||||
|
||||
private $config = array(
|
||||
'appid' => 'wxdf21b47ec5632158',
|
||||
'appsecret' => 'b319fbe508acdbc4c8d9ddaa5bd23444'
|
||||
);
|
||||
|
||||
public function __construct($options = array()) {
|
||||
$this->we_appid = isset($options['appid'])?$options['appid']:'';
|
||||
$this->we_appsecret = isset($options['appsecret'])?$options['appsecret']:'';
|
||||
|
||||
|
||||
$this->ci = & get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param int $appid (默认家加贷)
|
||||
*/
|
||||
public function init($appid = 1){
|
||||
switch($appid){
|
||||
case 2://小红榜
|
||||
break;
|
||||
case 3://座上宾
|
||||
break;
|
||||
default://家加贷
|
||||
$this->app = 'jjd';
|
||||
}
|
||||
|
||||
$config = $this->config;
|
||||
$this->we_appid = $config['appid'];
|
||||
$this->we_appsecret = $config['appsecret'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送小程序消息
|
||||
* @param $key(0放款, 1消费, 2扣款, 3照片审核成功, 4照片审核失败)
|
||||
* @param $openid
|
||||
* @param $params
|
||||
* @param string $page
|
||||
* @return bool
|
||||
*/
|
||||
public function send_app_msg($key, $openid, $params, $page = ''){
|
||||
$template_id = self::$tmpId_arr[$key];
|
||||
$status = true;
|
||||
$msg = '';
|
||||
//access_token
|
||||
$access_token = $this->get_access_token();
|
||||
|
||||
if(!$access_token){
|
||||
$status = false;
|
||||
$msg = 'not access_token';
|
||||
goto end;
|
||||
}
|
||||
|
||||
//form_id
|
||||
$form_id = $this->pop_form_id($openid);
|
||||
|
||||
if(!$form_id){
|
||||
$status = false;
|
||||
$msg = 'not form_id';
|
||||
goto end;
|
||||
}
|
||||
|
||||
$sdata = array(
|
||||
'touser' => $openid,
|
||||
'template_id' => $template_id,
|
||||
'form_id' => $form_id,
|
||||
'page' => $page,
|
||||
);
|
||||
|
||||
$sdata['data'] = $this->get_msg_data($key, $params);
|
||||
|
||||
$result = $this->http_post(self::API_URL_PREFIX.self::APP_MSG_URL.'?access_token='. $access_token, json_encode($sdata));
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$json = json_decode($result,true);
|
||||
if ($json['errcode']) {
|
||||
$status = false;
|
||||
$msg = $result;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
if(!$status) {debug_log($msg, 'wechat_msg.log');}
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取要提交的消息内容
|
||||
* @param $key
|
||||
* @param $params
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_msg_data($key, $params){
|
||||
switch($key){
|
||||
case 0://放款成功
|
||||
$arr = array(
|
||||
$params['time'],//日期
|
||||
$params['title'],//产品
|
||||
$params['user'],//客户
|
||||
$params['money'],//金额
|
||||
$params['descrip'],//流程阶段
|
||||
);
|
||||
break;
|
||||
case 1://消费成功
|
||||
$arr = array(
|
||||
$params['money'],//消费金额
|
||||
$params['balance'],//账户余额
|
||||
$params['id'],//订单号
|
||||
$params['time'],//消费时间
|
||||
$params['descrip'],//消费详情
|
||||
$params['addr'],//消费门店
|
||||
$params['shop'],//商户名称
|
||||
$params['type'],//支付方式
|
||||
$params['note'],//温馨提示
|
||||
);
|
||||
break;
|
||||
case 2://扣款成功
|
||||
$arr = array(
|
||||
$params['money'],//扣款金额
|
||||
$params['descrip'],//扣款原因
|
||||
$params['remark'],//备注
|
||||
);
|
||||
break;
|
||||
case 3://照片审核通过
|
||||
$arr = array(
|
||||
$params['title'],//审核项目
|
||||
$params['time'],//上传时间
|
||||
$params['descrip'],//审核结果
|
||||
$params['remark'],//备注信息
|
||||
);
|
||||
break;
|
||||
case 4://审核不通过
|
||||
$arr = array(
|
||||
$params['title'],//审核项目
|
||||
$params['time'],//上传时间
|
||||
$params['descrip'],//审核结果
|
||||
$params['note'],//拒绝理由
|
||||
$params['remark'],//备注信息
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$arr = array();
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach($arr as $k => $v){
|
||||
$kd = $k+1;
|
||||
$data["keyword{$kd}"] = array(
|
||||
'value' => $v,
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集新的form_id
|
||||
* @param $openid
|
||||
* @param $form_id
|
||||
* @param $expire (到期时间戳)
|
||||
* @return bool
|
||||
*/
|
||||
public function push_form_id($openid, $form_id, $expire = 0){
|
||||
//从redis获取
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
$key = "wechat_formid_{$this->we_appid}_{$openid}";
|
||||
$long = 7 * 24 * 3600;
|
||||
if($this->app){
|
||||
!$expire && $expire = time() + $long;
|
||||
$form = array('id' => $form_id, 'expire' => $expire);
|
||||
|
||||
$ret = $redis->lPush($key, json_encode($form));
|
||||
$len = $redis->lLen($key);
|
||||
//限制redis列表长度,去掉旧的
|
||||
$ret && $len > 100 && $redis->rPop($key);
|
||||
//更新redis有效期
|
||||
$redis->expire($key, $long);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* form_id数量
|
||||
* @param $openid
|
||||
* @return mixed
|
||||
*/
|
||||
public function count_form_id($openid){
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
$key = "wechat_formid_{$this->we_appid}_{$openid}";
|
||||
return $redis->lLen($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function clear($key = ''){
|
||||
if(!$key){return false;}
|
||||
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
return $redis->del($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取access_token
|
||||
* @return string
|
||||
*/
|
||||
private function get_access_token(){
|
||||
if($this->we_access_token){ return $this->we_access_token;}
|
||||
|
||||
if(!$this->we_appid){ return '';}
|
||||
|
||||
//从redis获取
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
$key = "wechat_accesstoken_{$this->we_appid}";
|
||||
if($this->app){
|
||||
$access_token = $this->we_access_token = $redis->get($key);
|
||||
if($access_token){return $access_token;}
|
||||
}
|
||||
|
||||
$url = self::API_URL_PREFIX . self::ACCESS_TOKEN_URL. "?grant_type=client_credential&appid={$this->we_appid}&secret={$this->we_appsecret}";
|
||||
$res = json_decode(file_get_contents($url), true);
|
||||
$access_token = $res['access_token'];
|
||||
|
||||
//存入redis
|
||||
if($access_token && $this->app){
|
||||
$redis->set($key, $access_token);
|
||||
$redis->expire($key, 7000);
|
||||
}
|
||||
|
||||
return $access_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $openid
|
||||
* @return int
|
||||
*/
|
||||
private function pop_form_id($openid){
|
||||
//从redis获取
|
||||
$r = &load_cache('redis');
|
||||
$redis = $r->redis();
|
||||
$key = "wechat_formid_{$this->we_appid}_{$openid}";
|
||||
|
||||
if($this->app){
|
||||
$now = time();
|
||||
while(1) {//循环获取fromid
|
||||
$form = $redis->rPop($key);
|
||||
$form && $form = json_decode($form, true);
|
||||
if(!$form){break;}
|
||||
if($form['expire'] >= $now){
|
||||
return $form['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求
|
||||
* @param string $url
|
||||
* @param array|string $param
|
||||
* @param boolean $post_file 是否文件上传
|
||||
* @return string content
|
||||
*/
|
||||
private 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);
|
||||
}
|
||||
if ($post_file){
|
||||
curl_setopt ($oCurl, CURLOPT_SAFE_UPLOAD, false);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user