初始化代码
This commit is contained in:
529
longbingcore/wxcore/DadaApi.php
Normal file
529
longbingcore/wxcore/DadaApi.php
Normal file
@@ -0,0 +1,529 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 达达开放平台sdk
|
||||
* User: 仝帅
|
||||
* Date: 2016-12-19
|
||||
* Time: 16:48
|
||||
*/
|
||||
class DadaApi
|
||||
{
|
||||
//private $URL = 'http://newopen.qa.imdada.cn';
|
||||
private $URL = 'http://newopen.imdada.cn';
|
||||
private $APP_KEY = '';
|
||||
private $VERSION = '1.0';
|
||||
private $APP_SECRET = '';
|
||||
private $API_ADDORDER = '/api/order/addOrder';
|
||||
private $API_FETCHORDER = '/api/order/fetch';
|
||||
private $API_CITY_LIST = "/api/cityCode/list";
|
||||
private $API_FINISHORDER = '/api/order/finish';
|
||||
private $API_CANCELORDER = '/api/order/cancel';
|
||||
private $API_EXPIREORDER = '/api/order/expire';
|
||||
private $API_FORMALCANCEL = '/api/order/formalCancel';
|
||||
private $API_CANCELREASONS = '/api/order/cancel/reasons';
|
||||
private $API_ACCEPTORDER = '/api/order/accept';
|
||||
private $API_ADDTIP = '/api/order/addTip';
|
||||
private $API_READDORDER = '/api/order/reAddOrder';
|
||||
|
||||
private $API_QUERYDELIVERFEE = '/api/order/queryDeliverFee';
|
||||
private $API_ADDAFTERQUERY = '/api/order/addAfterQuery';
|
||||
private $API_ADDSHOP = '/api/shop/add';
|
||||
private $API_ADDMERCHANT = '/merchantApi/merchant/add';
|
||||
|
||||
private $API_ORDERINFO = '/api/order/status/query';
|
||||
|
||||
|
||||
private $SOURCE_ID = '73753'; //商户编号
|
||||
private $SHOP_NO = '11047059'; //门店编号
|
||||
private $SUCCESS = "success";
|
||||
private $FAIL = "fail";
|
||||
|
||||
private $call_back;
|
||||
|
||||
public function __construct($appkey,$appsec,$source_id,$shop_no)
|
||||
{
|
||||
$this->APP_KEY = $appkey;
|
||||
|
||||
$this->APP_SECRET = $appsec;
|
||||
|
||||
$this->SHOP_NO = $shop_no;
|
||||
|
||||
$this->SOURCE_ID = $source_id;
|
||||
|
||||
$this->incon = '?';
|
||||
|
||||
// dump($this->APP_KEY , $this->APP_SECRET, $this->SHOP_NO , $this->SOURCE_ID);exit;
|
||||
|
||||
if(longbingIsWeiqin()){
|
||||
|
||||
// $url = substr($this->request->url(),0,strpos($this->request->url(), '&s='));
|
||||
|
||||
$params = $_GET;
|
||||
|
||||
$i=$params['i'];
|
||||
|
||||
$t=$params['t'];
|
||||
|
||||
$v=$params['v'];
|
||||
|
||||
$n=$params['m'];
|
||||
|
||||
$this->call_back = "https://".$_SERVER['HTTP_HOST']."/app/index.php?i=$i&t=".$t."&v=".$v."&from=wxapp&c=entry&a=wxapp&do=api&core=core2&m=".$n."&s=restaurant/SendResult/dadaSend";
|
||||
|
||||
// $this->call_back = 'http://'. $_SERVER['HTTP_HOST'].$url.'&s=/restaurant/SendResult/dadaSend';
|
||||
|
||||
$this->incon = '&';
|
||||
}else{
|
||||
|
||||
$this->call_back = 'http://'. $_SERVER['HTTP_HOST'].'/restaurant/SendResult/dadaSend';
|
||||
|
||||
$this->incon = '?';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 新增订单
|
||||
* @return bool
|
||||
*/
|
||||
public function addOrder($data)
|
||||
{
|
||||
|
||||
$city_code = $this->cityCode($data['city']);
|
||||
|
||||
if(!empty($city_code['code'])&&$city_code['code']==500){
|
||||
|
||||
return $city_code;
|
||||
|
||||
}
|
||||
|
||||
$arr = [
|
||||
|
||||
'shop_no' => $this->SHOP_NO,
|
||||
|
||||
'origin_id' => $data['order_code'],
|
||||
|
||||
'city_code' => $city_code,
|
||||
|
||||
'is_prepay' => 0,
|
||||
|
||||
'cargo_price' => $data['pay_price'],
|
||||
|
||||
'receiver_name' => $data['address']['name'],
|
||||
|
||||
'receiver_address' => $data['address']['address'].$data['address']['info'],
|
||||
|
||||
'receiver_phone' => $data['address']['phone'],
|
||||
|
||||
'receiver_lat' => $data['address']['lat'],
|
||||
|
||||
'receiver_lng' => $data['address']['long'],
|
||||
|
||||
'callback' => $this->call_back.$this->incon.'id='.$data['id'],
|
||||
|
||||
'cargo_weight' => $data['weight']
|
||||
|
||||
];
|
||||
|
||||
$res = self::getResult($this->API_ADDORDER,$arr);
|
||||
|
||||
|
||||
// dump($this->SHOP_NO,$res);exit;
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新发布订单
|
||||
* 在调用新增订单后,订单被取消、过期或者投递异常的情况下,调用此接口,可以在达达平台重新发布订单。
|
||||
* @return bool
|
||||
*/
|
||||
public function reAddOrder($data)
|
||||
{
|
||||
|
||||
$arr = [
|
||||
|
||||
'shop_no' => $this->SHOP_NO,
|
||||
|
||||
'origin_id' => $data['order_code'],
|
||||
|
||||
'city_code' => $this->cityCode($data['city']),
|
||||
|
||||
'is_prepay' => 0,
|
||||
|
||||
'cargo_price' => $data['pay_price'],
|
||||
|
||||
'receiver_name' => $data['address']['name'],
|
||||
|
||||
'receiver_address' => $data['address']['address'].$data['address']['info'],
|
||||
|
||||
'receiver_phone' => $data['address']['phone'],
|
||||
|
||||
'receiver_lat' => $data['address']['lat'],
|
||||
|
||||
'receiver_lng' => $data['address']['long'],
|
||||
|
||||
'callback' => $this->call_back.$this->incon.'id='.$data['id'],
|
||||
|
||||
'cargo_weight' => $data['weight']
|
||||
|
||||
];
|
||||
return self::getResult($this->API_READDORDER,$arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单运费接口
|
||||
* @return bool
|
||||
*/
|
||||
public function queryDeliverFee($data)
|
||||
{
|
||||
$data['shop_no'] = $this->SHOP_NO;
|
||||
|
||||
$arr = [
|
||||
|
||||
'shop_no' => $this->SHOP_NO,
|
||||
|
||||
'origin_id' => $data['id'],
|
||||
|
||||
'city_code' => $this->cityCode($data['city']),
|
||||
|
||||
'is_prepay' => 0,
|
||||
|
||||
'receiver_name' => $data['address']['name'],
|
||||
|
||||
'receiver_address' => $data['address']['address'].$data['address']['info'],
|
||||
|
||||
'receiver_phone' => $data['address']['phone'],
|
||||
|
||||
'receiver_lat' => $data['address']['lat'],
|
||||
|
||||
'receiver_lng' => $data['address']['long'],
|
||||
|
||||
'callback' => $this->call_back.$this->incon.'id='.$data['id'],
|
||||
|
||||
'cargo_weight' => $data['weight']
|
||||
|
||||
];
|
||||
|
||||
// dump($this->call_back.'/id/'.$data['id']);exit;
|
||||
return self::getResult($this->API_QUERYDELIVERFEE,$arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询运费后发单接口
|
||||
*/
|
||||
public function addAfterQuery($data)
|
||||
{
|
||||
|
||||
|
||||
return self::getResult($this->API_ADDAFTERQUERY,$data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询运费后发单接口
|
||||
*/
|
||||
public function orderInfo($data)
|
||||
{
|
||||
|
||||
$arr['order_id'] = $data['order_code'];
|
||||
// dump($data);exit;
|
||||
// $data['deliveryNo'] = '';
|
||||
return self::getResult($this->API_ORDERINFO,$arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单(线上环境)
|
||||
* 在订单待接单或待取货情况下,调用此接口可取消订单。注意:订单接单后1-15分钟取消订单,会扣除相应费用补贴给接单达达
|
||||
* @return bool
|
||||
*/
|
||||
public function formalCancel($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
// $data['cancel_reason_id'] = '1';
|
||||
// $data['cancel_reason'] = "";
|
||||
return self::getResult($this->API_FORMALCANCEL,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function cancelOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_CANCELORDER,$data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加小费
|
||||
* 可以对待接单状态的订单增加小费。需要注意:订单的小费,以最新一次加小费动作的金额为准,故下一次增加小费额必须大于上一次小费额。
|
||||
* @return bool
|
||||
*/
|
||||
public function addTip($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
// $data['tips'] = '2.5';
|
||||
// $data['city_code'] = '029';
|
||||
// $data['info'] = '';
|
||||
return self::getResult($this->API_ADDTIP,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增门店
|
||||
* @return bool
|
||||
*/
|
||||
public function addShop($data)
|
||||
{
|
||||
// $data['origin_shop_id'] = '';
|
||||
// $data['station_name'] = '';
|
||||
// $data['business'] = '';
|
||||
// $data['city_name'] = '';
|
||||
// $data['area_name'] = '';
|
||||
// $data['station_address'] = '';
|
||||
// $data['lng'] = '';
|
||||
// $data['lat'] = '';
|
||||
// $data['contact_name'] = '';
|
||||
// $data['phone'] = '';
|
||||
// $data['username'] = '';
|
||||
// $data['password'] = '';
|
||||
return self::getResult($this->API_ADDSHOP,$data);
|
||||
}
|
||||
|
||||
public function addMerchant($data)
|
||||
{
|
||||
// $data['mobile'] = '';
|
||||
// $data['city_name'] = '';
|
||||
// $data['enterprise_name'] = '';
|
||||
// $data['enterprise_address'] = '';
|
||||
// $data['contact_name'] = '';
|
||||
// $data['contact_phone'] = '';
|
||||
$this->SOURCE_ID = '';
|
||||
return self::getResult($this->API_ADDMERCHANT,$data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取取消订单原因列表
|
||||
* array {0 =>array{'reason' =>'没有达达接单','id' =>1},....}
|
||||
*/
|
||||
public function cancelReasons()
|
||||
{
|
||||
$res = self::getResult($this->API_CANCELREASONS);
|
||||
var_dump($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接单(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function acceptOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_ACCEPTORDER,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成取货(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function fetchOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_FETCHORDER,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成订单(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function finishOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_FINISHORDER,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单过期(仅在测试环境供调试使用)
|
||||
* @return bool
|
||||
*/
|
||||
public function expireOrder($data)
|
||||
{
|
||||
// $data['order_id'] = '12321';
|
||||
return self::getResult($this->API_EXPIREORDER,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单状态变化后,达达回调我们
|
||||
*/
|
||||
public function processCallback()
|
||||
{
|
||||
$content = file_get_contents("php://input");
|
||||
//{"order_status":2,"cancel_reason":"","update_time":1482220973,"dm_id":666,"signature":"7a177ae4b1cf63d13261580e4f721cb9","dm_name":"测试达达","order_id":"12321","client_id":"","dm_mobile":"13546670420"}
|
||||
if($content){
|
||||
$arr = json_decode($content,true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取城市信息
|
||||
* @return bool
|
||||
*/
|
||||
public function cityCode($city){
|
||||
|
||||
$code = 0;
|
||||
|
||||
$data = self::getResult($this->API_CITY_LIST);
|
||||
|
||||
if(empty($data['result'])){
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
$city = str_replace('市','',$city);
|
||||
|
||||
$found_key = array_search($city, array_column($data['result'], 'cityName'));
|
||||
|
||||
if(!is_numeric($found_key)){
|
||||
|
||||
return ['code'=>500,'msg'=>'达达暂不支持该城市'];
|
||||
}
|
||||
|
||||
if(key_exists($found_key,$data['result'])){
|
||||
|
||||
$code = $data['result'][$found_key]['cityCode'];
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $param
|
||||
* @param $time
|
||||
* @return string
|
||||
*/
|
||||
private function sign($param,$time)
|
||||
{
|
||||
$tmpArr = array(
|
||||
"app_key"=>$this->APP_KEY,
|
||||
"body"=>$param,
|
||||
"format"=>"json",
|
||||
"source_id"=>$this->SOURCE_ID,
|
||||
"timestamp"=>$time,
|
||||
"v"=>$this->VERSION,
|
||||
);
|
||||
|
||||
// dump($tmpArr);exit;
|
||||
if(empty($this->SOURCE_ID)){
|
||||
unset($tmpArr['source_id']);
|
||||
}
|
||||
$str = '';
|
||||
foreach ($tmpArr as $k=>$v){
|
||||
$str .= $k.$v;
|
||||
}
|
||||
$str = $this->APP_SECRET.$str.$this->APP_SECRET;
|
||||
$signature = md5($str);
|
||||
|
||||
// dump($signature);exit;
|
||||
return strtoupper($signature);
|
||||
}
|
||||
|
||||
private function getParam($data='')
|
||||
{
|
||||
if(empty($data)){
|
||||
$param = '';
|
||||
}else{
|
||||
$param = json_encode($data);
|
||||
}
|
||||
$time = time();
|
||||
$sign = self::sign($param,$time);
|
||||
$tmpArr = array(
|
||||
"app_key"=>$this->APP_KEY,
|
||||
"body"=>$param,
|
||||
"format"=>"json",
|
||||
"signature"=>$sign,
|
||||
"source_id"=>$this->SOURCE_ID,
|
||||
"timestamp"=>$time,
|
||||
"v"=>$this->VERSION,
|
||||
);
|
||||
if(empty($this->SOURCE_ID)){
|
||||
unset($tmpArr['source_id']);
|
||||
}
|
||||
|
||||
return json_encode($tmpArr);
|
||||
}
|
||||
|
||||
/** 根据参数获取结果信息
|
||||
* @param $api
|
||||
* @param string $data
|
||||
* @return bool
|
||||
*/
|
||||
private function getResult($api,$data=''){
|
||||
$param = self::getParam($data);
|
||||
|
||||
$url = $this->URL.$api;
|
||||
$res = self::http_post($url,$param);
|
||||
|
||||
if($res){
|
||||
$res = json_decode($res,true);
|
||||
// if($res['status'] == $this->SUCCESS){
|
||||
return $res;
|
||||
// }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求
|
||||
* @param string $url
|
||||
* @param array $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);
|
||||
}
|
||||
curl_setopt($oCurl, CURLOPT_URL, $url);
|
||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt($oCurl, CURLOPT_POST,true);
|
||||
curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
|
||||
$header = array(
|
||||
'Content-Type: application/json',
|
||||
);
|
||||
curl_setopt($oCurl, CURLOPT_HTTPHEADER, $header);
|
||||
|
||||
$sContent = curl_exec($oCurl);
|
||||
$aStatus = curl_getinfo($oCurl);
|
||||
curl_close($oCurl);
|
||||
if(intval($aStatus["http_code"])==200){
|
||||
return $sContent;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
298
longbingcore/wxcore/Excel.php
Normal file
298
longbingcore/wxcore/Excel.php
Normal file
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class Excel{
|
||||
|
||||
// static protected $uniacid;
|
||||
//
|
||||
// public function __construct($uniacid)
|
||||
// {
|
||||
// self::$uniacid = $uniacid;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @功能说明:读取excel文件 返回一个数组
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-02-13 18:21
|
||||
*/
|
||||
public function readExcel($filename){
|
||||
|
||||
//引用excel库
|
||||
require_once EXTEND_PATH.'PHPExcel/PHPExcel.php';
|
||||
//判断是否文件
|
||||
if(empty($filename)||!is_file($filename)){
|
||||
return '该文件错误';
|
||||
}
|
||||
//准备打开文件
|
||||
$objReader = \PHPExcel_IOFactory::createReaderForFile($filename);
|
||||
//载入文件
|
||||
$objPHPExcel = $objReader->load($filename);
|
||||
//设置第一个Sheet
|
||||
$objPHPExcel->setActiveSheetIndex(0);
|
||||
|
||||
$sheet = $objPHPExcel->getSheet(0);
|
||||
|
||||
$highestRow = $sheet->getHighestRow();
|
||||
|
||||
$highestColumn = $sheet->getHighestColumn();
|
||||
|
||||
for ($row = 2; $row <= $highestRow; $row++){
|
||||
//每一个文件
|
||||
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
|
||||
|
||||
$data[] = $rowData;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-09-10 10:47
|
||||
* @return \think\Response
|
||||
* descption:phpExcel 导出方法
|
||||
*/
|
||||
function excelExport($fileName = '', $headArr = [], $data = [],$type='',$status=0) {
|
||||
require_once EXTEND_PATH.'PHPExcel/PHPExcel.php';
|
||||
|
||||
ini_set("memory_limit", "1024M"); // 设置php可使用内存
|
||||
|
||||
set_time_limit(30);
|
||||
# 设置执行时间最大值
|
||||
// if(empty($fileName)){
|
||||
|
||||
$fileName .= ".xls";
|
||||
// }
|
||||
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
|
||||
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
||||
|
||||
$objPHPExcel->getProperties();
|
||||
|
||||
$key = ord("A"); // 设置表头
|
||||
|
||||
//dump($headArr);exit;
|
||||
$key2 = ord("@"); //64
|
||||
|
||||
foreach ($headArr as $v) {
|
||||
|
||||
$e=mb_detect_encoding($v, array('UTF-8', 'GBK'));
|
||||
|
||||
if($e!='UTF-8') {
|
||||
|
||||
$v = mb_convert_encoding($v, "UTF-8", "GBK");
|
||||
}
|
||||
|
||||
if($key > ord("Z"))
|
||||
{
|
||||
$colum = chr(ord("A")).chr(++$key2);//超过26个字母 AA1,AB1,AC1,AD1...BA1,BB1...
|
||||
}
|
||||
else
|
||||
{
|
||||
$colum = chr($key++);
|
||||
}
|
||||
|
||||
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
|
||||
|
||||
}
|
||||
$column = 2;
|
||||
|
||||
$objActSheet = $objPHPExcel->getActiveSheet(0);
|
||||
|
||||
if($type == 1){
|
||||
//合并名片的单元格
|
||||
$this->mergeCard($objPHPExcel);
|
||||
}
|
||||
|
||||
$fileName = iconv("utf-8", "GBK", $fileName);
|
||||
|
||||
foreach ($data as $key => $rows) { // 行写入
|
||||
|
||||
$span = ord("A");
|
||||
|
||||
$key2 = ord("@"); //64
|
||||
|
||||
foreach ($rows as $keyName => $value) { // 列写入
|
||||
|
||||
if($span > ord("Z"))
|
||||
{
|
||||
$colum = chr(ord("A")).chr(++$key2);//超过26个字母 AA1,AB1,AC1,AD1...BA1,BB1...
|
||||
}
|
||||
else
|
||||
{
|
||||
$colum = chr($span);
|
||||
}
|
||||
|
||||
if(!empty($value)&&is_string($value)){
|
||||
|
||||
$e=mb_detect_encoding($value, array('UTF-8', 'GBK'));
|
||||
|
||||
$value = $this->filterEmoji($value);
|
||||
|
||||
if($e!='UTF-8'){
|
||||
|
||||
$value = mb_convert_encoding($value, "UTF-8", "GBK");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$objActSheet->setCellValueExplicit($colum . $column, $value);
|
||||
|
||||
$span++;
|
||||
}
|
||||
$column++;
|
||||
}
|
||||
|
||||
if(!empty($status)){
|
||||
|
||||
$this->mergeOrderExcel($objPHPExcel,$data,$status);
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
|
||||
header("Content-Disposition: attachment;filename=$fileName");
|
||||
|
||||
header('Cache-Control: max-age=0');
|
||||
|
||||
header('content-Type:application/vnd.ms-excel;charset=utf-8');
|
||||
|
||||
$objWriter->save('php://output');// 文件通过浏览器下载
|
||||
|
||||
return $fileName;
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
* @param $data
|
||||
* 合并订单单元格
|
||||
*/
|
||||
public function mergeOrderExcel($obj,$data,$status=1){
|
||||
|
||||
foreach ($data as $k=>$v){
|
||||
|
||||
if(!empty($v)){
|
||||
|
||||
$v['key'] = $k+2;
|
||||
|
||||
$newdata[$v[0]][] = $v;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
switch ($status){
|
||||
case '1' :
|
||||
$arr = ['A','E','F','G','H','I','J','K','L','M','N','O','P'];
|
||||
break;
|
||||
|
||||
case '2' :
|
||||
$arr = ['A','E','F','G','H','I','J','K','L','M','N','O'];
|
||||
break;
|
||||
case '3' :
|
||||
$arr = ['A','F','G','H','I','J','K','L'];
|
||||
break;
|
||||
|
||||
}
|
||||
foreach ($newdata as $k=>$v){
|
||||
if(count($v)>1){
|
||||
$count = count($v)-1;
|
||||
foreach ($arr as $value){
|
||||
$me = $value.$v[0]['key'].':'.$value.$v[$count]['key'];
|
||||
|
||||
$obj->getActiveSheet()->mergeCells($me);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return string|string[]|null
|
||||
* 过滤表情包
|
||||
*/
|
||||
public function filterEmoji($str)
|
||||
{
|
||||
$str = preg_replace_callback(
|
||||
'/./u',
|
||||
function (array $match) {
|
||||
return strlen($match[0]) >= 4 ? '' : $match[0];
|
||||
},
|
||||
$str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-15 15:19
|
||||
* @功能说明:合并订单导出的单元格
|
||||
*/
|
||||
public function mergeCard($objPHPExcel){
|
||||
|
||||
|
||||
$arr = ['A','B','C','D'];
|
||||
|
||||
foreach ($arr as $value){
|
||||
|
||||
$s_icon = $value.'1'.':'.$value.'2';
|
||||
|
||||
$h_icon = $value.'1';
|
||||
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($s_icon);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getstyle($s_icon)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle($h_icon)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
}
|
||||
|
||||
$arr2 = ['E1:F1','G1:H1','I1:J1','K1:L1','M1:N1','O1:P1'];
|
||||
|
||||
foreach ($arr2 as $value){
|
||||
|
||||
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($value);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getstyle($value)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle($value)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
}
|
||||
|
||||
$arr3 = ['E2','F2','G2','H2','I2','J2','K2','L2','M2','N2','O2','P2'];
|
||||
|
||||
foreach ($arr3 as $value){
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle($value)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
178
longbingcore/wxcore/PayModel.php
Normal file
178
longbingcore/wxcore/PayModel.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\ApiRest;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class PayModel extends ApiRest {
|
||||
|
||||
// static protected $uniacid;
|
||||
|
||||
public function __construct($pay_config)
|
||||
{
|
||||
$this->pay_config = $pay_config;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-17 14:36
|
||||
* @功能说明:
|
||||
*/
|
||||
public function findOrder(){
|
||||
|
||||
$pay_config = $this->payConfig();
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeQueryRequest.php';
|
||||
|
||||
$aop = new \AopClient ();
|
||||
|
||||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||||
// $aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
|
||||
|
||||
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
|
||||
|
||||
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];
|
||||
|
||||
$aop->alipayrsaPublicKey=$pay_config['payment']['ali_publickey'];
|
||||
$aop->apiVersion = '1.0';
|
||||
$aop->signType = 'RSA2';
|
||||
$aop->postCharset='UTF-8';
|
||||
$aop->format='json';
|
||||
$object = new \stdClass();
|
||||
$object->out_trade_no = '20150320010101001';
|
||||
//$object->trade_no = '2014112611001004680073956707';
|
||||
$json = json_encode($object);
|
||||
$request = new \AlipayTradeQueryRequest();
|
||||
$request->setBizContent($json);
|
||||
|
||||
$result = $aop->execute ( $request);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-10 16:36
|
||||
* @功能说明:支付宝支付
|
||||
*/
|
||||
public function aliPay($order_code,$price,$subject){
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeAppPayRequest.php';
|
||||
|
||||
$pay_config = $this->payConfig();
|
||||
|
||||
$aop = new \AopClient ();
|
||||
|
||||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||||
|
||||
$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
|
||||
|
||||
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
|
||||
|
||||
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];;
|
||||
|
||||
$aop->alipayrsaPublicKey= $pay_config['payment']['ali_publickey'];;
|
||||
|
||||
$aop->apiVersion = '1.0';
|
||||
|
||||
$aop->signType = 'RSA2';
|
||||
|
||||
$aop->postCharset='UTF-8';
|
||||
|
||||
$aop->format='json';
|
||||
|
||||
$object = new \stdClass();
|
||||
|
||||
$object->out_trade_no = $order_code;
|
||||
|
||||
$object->total_amount = $price;
|
||||
|
||||
$object->subject = $subject;
|
||||
|
||||
$object->product_code ='QUICK_MSECURITY_PAY';
|
||||
|
||||
//$object->time_expire = date('Y-m-d H:i:s',time());
|
||||
|
||||
$json = json_encode($object);
|
||||
|
||||
$request = new \AlipayTradeAppPayRequest();
|
||||
|
||||
$request->setNotifyUrl("https://".$_SERVER['HTTP_HOST'].'/index.php/shop/IndexWxPay/aliNotify');
|
||||
|
||||
$request->setBizContent($json);
|
||||
|
||||
$result = $aop->sdkExecute ( $request);
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-11 17:23
|
||||
* @功能说明:退款
|
||||
*/
|
||||
public function aliRefund($order_code,$price){
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
|
||||
|
||||
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeRefundRequest.php';
|
||||
|
||||
$pay_config = $this->payConfig();
|
||||
|
||||
$aop = new \AopClient ();
|
||||
|
||||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||||
|
||||
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
|
||||
|
||||
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];;
|
||||
|
||||
$aop->alipayrsaPublicKey= $pay_config['payment']['ali_publickey'];;
|
||||
|
||||
$aop->apiVersion = '1.0';
|
||||
|
||||
$aop->signType = 'RSA2';
|
||||
|
||||
$aop->postCharset='UTF-8';
|
||||
|
||||
$aop->format='json';
|
||||
|
||||
$object = new \stdClass();
|
||||
|
||||
$object->trade_no = $order_code;
|
||||
|
||||
$object->refund_amount = $price;
|
||||
|
||||
$object->out_request_no = 'HZ01RF001';
|
||||
|
||||
$json = json_encode($object);
|
||||
|
||||
$request = new \AlipayTradeRefundRequest();
|
||||
|
||||
$request->setBizContent($json);
|
||||
|
||||
$result = $aop->execute ( $request);
|
||||
|
||||
$result = !empty($result)?object_array($result):[];
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
72
longbingcore/wxcore/PayNotify.php
Normal file
72
longbingcore/wxcore/PayNotify.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\ApiRest;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class PayNotify {
|
||||
|
||||
// static protected $uniacid;
|
||||
|
||||
// public function __construct(App $app)
|
||||
// {
|
||||
// $this->app = $app;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-19 13:29
|
||||
* @功能说明:支付宝回调信息
|
||||
*/
|
||||
public function aliNotify($arr){
|
||||
|
||||
switch ($arr['subject']){
|
||||
|
||||
case '余额充值':
|
||||
//余额卡
|
||||
$order_model = new \app\farm\model\BalanceOrder();
|
||||
|
||||
break;
|
||||
|
||||
case '认养商品':
|
||||
//认养
|
||||
$order_model = new \app\farm\model\ClaimOrder();
|
||||
|
||||
break;
|
||||
case '土地商品':
|
||||
//土地
|
||||
$order_model = new \app\farm\model\LandOrder();
|
||||
|
||||
break;
|
||||
|
||||
case '配送订单':
|
||||
//配送订单
|
||||
$order_model = new \app\farm\model\SendOrder();
|
||||
|
||||
break;
|
||||
|
||||
case '养殖商品':
|
||||
//养殖订单
|
||||
$order_model = new \app\farm\model\BreedOrder();
|
||||
|
||||
break;
|
||||
case '商场商品':
|
||||
//商城订单
|
||||
$order_model = new \app\farm\model\ShopOrder();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$order_model->orderResult($arr['out_trade_no'],$arr['trade_no']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
156
longbingcore/wxcore/PospalApi.php
Normal file
156
longbingcore/wxcore/PospalApi.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 达达开放平台sdk
|
||||
* User: 仝帅
|
||||
* Date: 2016-12-19
|
||||
* Time: 16:48
|
||||
*/
|
||||
class PospalApi
|
||||
{
|
||||
|
||||
protected $appId;
|
||||
|
||||
protected $appKey;
|
||||
|
||||
protected $signature;
|
||||
|
||||
protected $url;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->appId = '205871490509191130';
|
||||
$this->appId = '9C7F3BFC37E729D9A5D6798B2D358E28';
|
||||
|
||||
$this->url = 'https://area56-win.pospal.cn:443/';
|
||||
|
||||
$this->account_key = '0e73963b251112af12835cd7d6dbadca';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:42
|
||||
* @功能说明:获取令牌
|
||||
*/
|
||||
|
||||
public function getToken(){
|
||||
|
||||
$url = 'https://api.ubibot.cn/accounts/generate_access_token?account_key='.$this->account_key;
|
||||
|
||||
$key = 'ubibot_token';
|
||||
|
||||
$data = getCache($key);
|
||||
|
||||
if(empty($data)){
|
||||
|
||||
$data = $this->request($url,[],'GET');
|
||||
|
||||
if(!empty($data['result'])&&$data['result']=='success'){
|
||||
|
||||
setCache($key,$data,60);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:54
|
||||
* @功能说明:获取空间列表
|
||||
*/
|
||||
public function getRoomList(){
|
||||
|
||||
$url = 'https://api.ubibot.cn/channels?account_key='.$this->account_key;
|
||||
|
||||
$data = $this->request($url,[],'GET');
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:57
|
||||
* @功能说明:获取空间详情
|
||||
*/
|
||||
public function getRoomInfo($room_id){
|
||||
|
||||
$url = 'https://api.ubibot.cn/channels/'.$room_id.'?account_key='.$this->account_key;
|
||||
|
||||
$data = $this->request($url,[],'GET');
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $post_data
|
||||
* @param string $post_type
|
||||
* @功能说明:发送请求
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-26 14:38
|
||||
*/
|
||||
public function request($url,$post_data,$post_type='POST'){
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
$post_data = json_encode($post_data);
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => $post_type,
|
||||
CURLOPT_POSTFIELDS => $post_data,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Content-Type:application/json",
|
||||
"User-Agent:openApi",
|
||||
"Content-Type:application/json; charset=utf-8",
|
||||
"accept-encoding:gzip,deflate",
|
||||
"time-stamp:".time(),
|
||||
// "data-signature:D2C3D3C7289EAE111277999D21196D4D",
|
||||
"data-signature:".strtoupper(md5($this->appKey.$post_data))
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
return json_decode($response,true);
|
||||
|
||||
// if ($err) {
|
||||
// echo "cURL Error #:" . $err;
|
||||
// } else {
|
||||
// echo $response;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
241
longbingcore/wxcore/PushMsgModel.php
Normal file
241
longbingcore/wxcore/PushMsgModel.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\ApiRest;
|
||||
use app\farm\controller\IndexInfo;
|
||||
use app\farm\model\Config;
|
||||
use app\farm\model\SystemInfo;
|
||||
use app\farm\model\User;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
|
||||
class PushMsgModel {
|
||||
|
||||
|
||||
private $app_key;
|
||||
//待发送的应用程序(appKey),只能填一个。
|
||||
private $master_secret;
|
||||
//主密码
|
||||
private $url; //推送的地址
|
||||
//若实例化的时候传入相应的值则按新的相应值进行
|
||||
public function __construct($uniacid) {
|
||||
|
||||
$config_model = new Config();
|
||||
|
||||
$config = $config_model->dataInfo(['uniacid'=>$uniacid]);
|
||||
|
||||
$this->app_key = $config['push_key'];
|
||||
|
||||
$this->master_secret = $config['push_secret'];
|
||||
|
||||
$this->url = 'https://api.jpush.cn/v3/push';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* $receiver 接收者的信息
|
||||
all 字符串 该产品下面的所有用户. 对app_key下的所有用户推送消息
|
||||
tag(20个)Array标签组(并集): tag=>array('昆明','北京','曲靖','上海');
|
||||
tag_and(20个)Array标签组(交集): tag_and=>array('广州','女');
|
||||
alias(1000)Array别名(并集): alias=>array('93d78b73611d886a74*****88497f501','606d05090896228f66ae10d1*****310');
|
||||
registration_id(1000)注册ID设备标识(并集): registration_id=>array('20effc071de0b45c1a**********2824746e1ff2001bd80308a467d800bed39e');
|
||||
*/
|
||||
//$content 推送的内容。
|
||||
//$m_type 推送附加字段的类型(可不填) http,tips,chat....
|
||||
//$m_txt 推送附加字段的类型对应的内容(可不填) 可能是url,可能是一段文字。
|
||||
//$m_time 保存离线时间的秒数默认为一天(可不传)单位为秒
|
||||
/**
|
||||
* @param string $receiver 目标用户
|
||||
* @param string $content
|
||||
* @param string $m_type
|
||||
* @param string $m_txt
|
||||
* @param string $m_time
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-22 16:45
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function push($receiver='all',$content='',$m_type='',$m_txt='',$m_time='86400')
|
||||
{
|
||||
|
||||
if(empty($this->app_key)||empty($this->master_secret)){
|
||||
|
||||
return false;
|
||||
}
|
||||
// dump($this->app_key);exit;
|
||||
$base64 = base64_encode("$this->app_key:$this->master_secret");
|
||||
$header = array("Authorization:Basic $base64", "Content-Type:application/json");
|
||||
$data = array();
|
||||
$data['platform'] = 'all'; //目标用户终端手机的平台类型android,ios,winphone
|
||||
$data['audience'] = $receiver; //目标用户
|
||||
|
||||
$data['notification'] = array(
|
||||
//统一的模式--标准模式
|
||||
"alert" => $content,
|
||||
//安卓自定义
|
||||
"android" => array(
|
||||
"alert" => $content,
|
||||
"title" => "",
|
||||
"builder_id" => 1,
|
||||
"extras" => array("type" => $m_type, "txt" => $m_txt)
|
||||
),
|
||||
//ios的自定义
|
||||
"ios" => array(
|
||||
"alert" => $content,
|
||||
"badge" => "1",
|
||||
"sound" => "default",
|
||||
"extras" => array("type" => $m_type, "txt" => $m_txt)
|
||||
)
|
||||
);
|
||||
//苹果自定义---为了弹出值方便调测
|
||||
$data['message'] = array(
|
||||
"msg_content"=>$content,
|
||||
"extras"=>array("type"=>$m_type, "txt"=>$m_txt)
|
||||
);
|
||||
|
||||
//附加选项
|
||||
$data['options'] = array(
|
||||
"sendno"=>time(),
|
||||
// "time_to_live"=>$m_time, //保存离线时间的秒数默认为一天
|
||||
"apns_production"=>false, //布尔类型 指定 APNS 通知发送环境:0开发环境,1生产环境。或者传递false和true
|
||||
);
|
||||
$param = json_encode($data);
|
||||
$res = $this->push_curl($param,$header);
|
||||
|
||||
if($res){ //得到返回值--成功已否后面判断
|
||||
return $res;
|
||||
}else{ //未得到返回值--返回失败
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function push_curl($param="",$header="") {
|
||||
if (empty($param)) { return false; }
|
||||
$postUrl = $this->url;
|
||||
$curlPost = $param;
|
||||
$ch = curl_init(); //初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL,$postUrl); //抓取指定网页
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
|
||||
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,$header); // 增加 HTTP Header(头)里的字段
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 终止从服务端进行验证
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
$data = curl_exec($ch); //运行curl
|
||||
curl_close($ch);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $type
|
||||
* @功能说明:
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-23 13:54
|
||||
*/
|
||||
public function sendMsg($data,$type){
|
||||
|
||||
$info_model = new SystemInfo();
|
||||
|
||||
$user_model = new User();
|
||||
//添加信息
|
||||
$info_model->infoAdd($data,$type);
|
||||
|
||||
$data = $info_model->returnMsg($type,$data);
|
||||
|
||||
$push_id = $user_model->where(['id'=>$data['user_id']])->value('push_id');
|
||||
|
||||
if(!empty($push_id)){
|
||||
|
||||
$push_id = ['registration_id'=>[$push_id]];
|
||||
//发送消息
|
||||
$this->send_pub($data['msg'],$push_id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-22 16:46
|
||||
* @功能说明:
|
||||
*/
|
||||
public function send_pub($content,$receive='all'){
|
||||
//推送附加字段的类型
|
||||
$m_type = 'http';
|
||||
//推送附加字段的类型对应的内容(可不填) 可能是url,可能是一段文字。
|
||||
$m_txt = 'http://www.groex.cn/';
|
||||
//离线保留时间
|
||||
$m_time = '86400';
|
||||
|
||||
$result = $this->push($receive,$content,$m_type,$m_txt,$m_time);
|
||||
|
||||
$res_arr=!empty($result)?json_decode($result, true):[];
|
||||
|
||||
return $res_arr;
|
||||
|
||||
if($result){
|
||||
|
||||
$res_arr = json_decode($result, true);
|
||||
|
||||
|
||||
if(isset($res_arr['error'])){
|
||||
//错误信息
|
||||
$error_code=$res_arr['error']['code'];
|
||||
//错误码
|
||||
switch ($error_code) {
|
||||
case 200:
|
||||
$message= '发送成功!';
|
||||
break;
|
||||
case 1000:
|
||||
$message= '失败(系统内部错误)';
|
||||
break;
|
||||
case 1001:
|
||||
$message = '失败(只支持 HTTP Post 方法,不支持 Get 方法)';
|
||||
break;
|
||||
case 1002:
|
||||
$message= '失败(缺少了必须的参数)';
|
||||
break;
|
||||
case 1003:
|
||||
$message= '失败(参数值不合法)';
|
||||
break;
|
||||
case 1004:
|
||||
$message= '失败(验证失败)';
|
||||
break;
|
||||
case 1005:
|
||||
$message= '失败(消息体太大)';
|
||||
break;
|
||||
case 1008:
|
||||
$message= '失败(appkey参数非法)';
|
||||
break;
|
||||
case 1020:
|
||||
$message= '失败(只支持 HTTPS 请求)';
|
||||
break;
|
||||
case 1030:
|
||||
$message= '失败(内部服务超时)';
|
||||
break;
|
||||
default:
|
||||
$message= '失败(返回其他状态,目前不清楚额,请联系开发人员!)';
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
$message="发送成功!";
|
||||
}
|
||||
}else{ //接口调用失败或无响应
|
||||
$message='接口调用失败或无响应';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
138
longbingcore/wxcore/WxMsg.php
Normal file
138
longbingcore/wxcore/WxMsg.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\extend\wxWork\work;
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class WxMsg{
|
||||
|
||||
static protected $uniacid;
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
self::$uniacid = $uniacid;
|
||||
|
||||
$this->config = $this->getConfig($uniacid);
|
||||
|
||||
$this->appid = $this->getAppid();
|
||||
|
||||
// $this->appsecret = $this->getAppsecret();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-27 17:35
|
||||
* @功能说明:企业微信消息
|
||||
*/
|
||||
public function WxMsg($to_user,$title='',$page='',$description='',$content_item=''){
|
||||
|
||||
$data = [
|
||||
//接受者
|
||||
'touser' => $to_user,
|
||||
//类型
|
||||
'msgtype'=> 'miniprogram_notice',
|
||||
|
||||
'miniprogram_notice' => [
|
||||
|
||||
'appid' => $this->appid ,
|
||||
//放大第一个字段
|
||||
// 'emphasis_first_item' => true,
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
if(!empty($page)){
|
||||
//路径
|
||||
$data['miniprogram_notice']['page'] = $page;
|
||||
}
|
||||
if(!empty($title)){
|
||||
//标题
|
||||
$data['miniprogram_notice']['title'] = $title;
|
||||
}
|
||||
if(!empty($content_item)){
|
||||
//内容
|
||||
$data['miniprogram_notice']['content_item'] = $content_item;
|
||||
}
|
||||
if(!empty($description)){
|
||||
//描述
|
||||
$data['miniprogram_notice']['description'] = $description;
|
||||
}
|
||||
//初始化配置模型
|
||||
$service_model = new WxSetting(self::$uniacid);
|
||||
//发送消息
|
||||
$result = $service_model->sendCompanyMsg($data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 功能说明 获取appid
|
||||
*
|
||||
* @return mixed|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:36
|
||||
*/
|
||||
protected function getAppid()
|
||||
{
|
||||
if(isset($this->config['appid'])) return $this->config['appid'];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取appsecret
|
||||
*
|
||||
* @return mixed|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:36
|
||||
*/
|
||||
protected function getAppsecret()
|
||||
{
|
||||
if(isset($this->config['app_secret'])) return $this->config['app_secret'];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取配置信息
|
||||
*
|
||||
* @param $uniacid
|
||||
* @return array|bool|mixed|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:35
|
||||
*/
|
||||
public function getConfig($uniacid)
|
||||
{
|
||||
//config key
|
||||
$key = 'longbing_card_app_config_' . $uniacid;
|
||||
//获取config
|
||||
$config = getCache($key, $uniacid);
|
||||
//判断缓存是否存在
|
||||
if(!empty($config)) return $config;
|
||||
//获取数据
|
||||
$config = Db::name('longbing_card_config')->where(['uniacid'=>$uniacid])->find();
|
||||
|
||||
if(empty($config)){
|
||||
Db::name('longbing_card_config')->insert(['uniacid'=>$uniacid]);
|
||||
$config = Db::name('longbing_card_config')->where(['uniacid'=>$uniacid])->find();
|
||||
}
|
||||
//判断数据是否存在
|
||||
if(!empty($config)) setCache($key ,$config ,3600,$uniacid);
|
||||
//返回数据
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
113
longbingcore/wxcore/WxPay.php
Normal file
113
longbingcore/wxcore/WxPay.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class WxPay{
|
||||
|
||||
static protected $uniacid;
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
self::$uniacid = $uniacid;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取支付信息
|
||||
*/
|
||||
public function payConfig (){
|
||||
$uniacid_id = self::$uniacid;
|
||||
|
||||
$pay = Db::name('longbing_card_config_pay')->where(['uniacid'=>$uniacid_id])->find();
|
||||
$config = Db::name( 'longbing_card_config')->where(['uniacid' => $uniacid_id])->find();
|
||||
if(empty($pay[ 'mch_id' ])||empty($pay[ 'pay_key' ])){
|
||||
|
||||
return [
|
||||
|
||||
'result_code' => false,
|
||||
|
||||
'return_code' => false,
|
||||
|
||||
'err_code_des'=> '未配置支付信息'
|
||||
];
|
||||
}
|
||||
$setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ];
|
||||
$setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ];
|
||||
$setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ];
|
||||
$setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ];
|
||||
$setting[ 'app_id' ] = $config['appid'];
|
||||
$setting[ 'secret' ] = $config['app_secret'];
|
||||
return $setting;
|
||||
}
|
||||
/**
|
||||
* @param string $uid
|
||||
* @param string $money
|
||||
* @功能说明:提现
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-03-24 14:52
|
||||
*/
|
||||
public function crteateMchPay($paymentApp,$openid,$money='')
|
||||
{
|
||||
|
||||
$money = $money*100;
|
||||
|
||||
$payid = substr(md5('longbing1'.time()),0,11);
|
||||
//没有配置支付信息
|
||||
if(empty($paymentApp['app_id'])||empty($paymentApp['payment']['merchant_id'])){
|
||||
|
||||
return $paymentApp;
|
||||
|
||||
}
|
||||
//没有openid
|
||||
if(empty($openid)){
|
||||
|
||||
return [
|
||||
|
||||
'result_code' => false,
|
||||
|
||||
'return_code' => false,
|
||||
|
||||
'err_code_des'=> '用户信息错误'
|
||||
];
|
||||
}
|
||||
|
||||
$setting['mini_appid'] = $paymentApp['app_id'];
|
||||
$setting['mini_appsecrept'] = $paymentApp['secret'];
|
||||
$setting['mini_mid'] = $paymentApp['payment']['merchant_id'];
|
||||
$setting['mini_apicode'] = $paymentApp['payment']['key'];
|
||||
$setting['apiclient_cert'] = $paymentApp['payment']['cert_path'];
|
||||
$setting['apiclient_cert_key'] = $paymentApp['payment']['key_path'];
|
||||
|
||||
|
||||
define('WX_APPID', $setting['mini_appid']);
|
||||
define('WX_MCHID', $setting['mini_mid']);
|
||||
define('WX_KEY', $setting['mini_apicode']);
|
||||
define('WX_APPSECRET', $setting['mini_appsecrept']);
|
||||
define('WX_SSLCERT_PATH', $setting['apiclient_cert']);
|
||||
define('WX_SSLKEY_PATH', $setting['apiclient_cert_key']);
|
||||
define('WX_CURL_PROXY_HOST', '0.0.0.0');
|
||||
define('WX_CURL_PROXY_PORT', 0);
|
||||
define('WX_REPORT_LEVENL', 0);
|
||||
|
||||
require_once PAY_PATH . "weixinpay/lib/WxPay.Api.php";
|
||||
require_once PAY_PATH . "weixinpay/example/WxPay.JsApiPay.php";
|
||||
require_once PAY_PATH . "weixinpay/lib/WxMchPay.php";
|
||||
$payClass=new \WxMchPay();
|
||||
|
||||
$res=$payClass->MchPayOrder($openid,$money,$payid);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
449
longbingcore/wxcore/WxSetting.php
Normal file
449
longbingcore/wxcore/WxSetting.php
Normal file
@@ -0,0 +1,449 @@
|
||||
<?php
|
||||
/*
|
||||
* 服务通知
|
||||
*
|
||||
*************************************/
|
||||
namespace longbingcore\wxcore;
|
||||
use app\admin\model\AppConfig;
|
||||
use app\sendmsg\model\SendConfig;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
class WxSetting
|
||||
{
|
||||
//accesstoken
|
||||
protected $access_token = null;
|
||||
//appid
|
||||
protected $appid = null;
|
||||
//appsecret
|
||||
protected $appsecret = null;
|
||||
//uniacid
|
||||
protected $uniacid = '7777';
|
||||
//配置信息
|
||||
protected $config = [];
|
||||
//初始化
|
||||
function __construct($uniacid = '1'){
|
||||
$this->uniacid = $uniacid;
|
||||
|
||||
$this->config = $this->getConfig($this->uniacid);
|
||||
|
||||
$this->appid = $this->getAppid();
|
||||
|
||||
$this->appsecret = $this->getAppsecret();
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取appid
|
||||
*
|
||||
* @return mixed|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:36
|
||||
*/
|
||||
protected function getAppid()
|
||||
{
|
||||
if(isset($this->config['appid'])) return $this->config['appid'];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取appsecret
|
||||
*
|
||||
* @return mixed|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:36
|
||||
*/
|
||||
protected function getAppsecret()
|
||||
{
|
||||
if(isset($this->config['appsecret'])) return $this->config['appsecret'];
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取配置信息
|
||||
*
|
||||
* @param $uniacid
|
||||
* @return array|bool|mixed|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:35
|
||||
*/
|
||||
public function getConfig($uniacid)
|
||||
{
|
||||
|
||||
$config = longbingGetAppConfig($uniacid);
|
||||
//返回数据
|
||||
return $config;
|
||||
}
|
||||
|
||||
//检查信息是否存在
|
||||
public function checkConfig()
|
||||
{
|
||||
$result = true;
|
||||
if(empty($this->uniacid) || empty($this->appid) || empty($this->appsecret)) $result = false;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能说明 获取token
|
||||
*
|
||||
* @return bool|null
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 17:35
|
||||
*/
|
||||
public function lbSingleGetAccessToken ()
|
||||
{
|
||||
$key = "longbing_card_access_token";
|
||||
|
||||
$value = getCache( $key,$this->uniacid );
|
||||
|
||||
|
||||
if ( $value !=false )
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
$uniacid = $this->uniacid;
|
||||
//基础检查
|
||||
if(!$this->checkConfig()){
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
//appid
|
||||
$appid = $this->appid;
|
||||
//appsecret
|
||||
$appsecret = $this->appsecret;
|
||||
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret={$appsecret}";
|
||||
|
||||
|
||||
$accessToken = file_get_contents( $url );
|
||||
|
||||
// dump($accessToken);exit;
|
||||
|
||||
if ( strstr( $accessToken, 'errcode' ) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$accessToken = json_decode( $accessToken, true );
|
||||
$accessToken = $accessToken[ 'access_token' ];
|
||||
|
||||
setCache( $key, $accessToken, 7000, $uniacid );
|
||||
|
||||
return $accessToken;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-12-25 11:52
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* descrption:添加模版 返回模版消息id
|
||||
*/
|
||||
public function addTmpl($data){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
// dump($access_token);exit;
|
||||
//添加模版的小程序地址
|
||||
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token={$access_token}";
|
||||
//请求
|
||||
$data = json_encode( $data, JSON_UNESCAPED_UNICODE );
|
||||
//返回模版消息id 是个array
|
||||
$res = $this->curlPost( $url,$data );
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 11:39
|
||||
* @功能说明:获取所有模版消息列表
|
||||
*/
|
||||
public function getAllTpmlList(){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//获取小程序所有 模版消息的url
|
||||
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token={$access_token}";
|
||||
//请求
|
||||
$res = $this->curlPost($url,NULL,'GET');
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $tpml_id
|
||||
* @功能说明: 删除模版消息
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 14:08
|
||||
*/
|
||||
public function deleteTmpl($tpml_id){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//获取小程序所有 模版消息的url
|
||||
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token={$access_token}";
|
||||
//请求参数
|
||||
$data['priTmplId'] = $tpml_id;
|
||||
//请求
|
||||
$data = json_encode( $data, JSON_UNESCAPED_UNICODE );
|
||||
$res = $this->curlPost($url,$data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 18:54
|
||||
* @功能说明:发送模版消息
|
||||
*/
|
||||
public function sendTmpl($data){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//获取小程序所有 模版消息的url
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$access_token}";
|
||||
//请求
|
||||
$data = json_encode( $data, JSON_UNESCAPED_UNICODE );
|
||||
// dump($data);exit;
|
||||
$res = $this->curlPost($url,$data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 18:54
|
||||
* @功能说明:获取当前账号下的所有模版消息
|
||||
*/
|
||||
public function getUserTmpl(){
|
||||
//获取token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//获取小程序所有 模版消息的url
|
||||
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token={$access_token}";
|
||||
//请求
|
||||
$res = $this->curlPost($url,[],'GET');
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @功能说明:企业微信消息
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-27 18:33
|
||||
*/
|
||||
public function sendCompanyMsg(array $data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
$accessTokenWW = $this->companyMsgToken();
|
||||
|
||||
$url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$accessTokenWW}";
|
||||
|
||||
$res = $this->curlPost($url, $data);
|
||||
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-04-28 13:40
|
||||
* @功能说明:获取企业消息token
|
||||
*/
|
||||
public function companyMsgToken(){
|
||||
|
||||
$key = "longbing_card_access_token_qy_cn";
|
||||
|
||||
$value = getCache($key,$this->uniacid);
|
||||
|
||||
if ( $value !== false )
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
$send_model = new SendConfig();
|
||||
//配置信息
|
||||
$config = $send_model->configInfo(['uniacid'=>$this->uniacid]);
|
||||
|
||||
if (!empty($config['yq_corpid'])&& !empty($config['yq_corpsecret'] ))
|
||||
{
|
||||
$key = $config['yq_corpid'];
|
||||
|
||||
$secret = $config['yq_corpsecret'];
|
||||
|
||||
$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$key&corpsecret=$secret";
|
||||
|
||||
$accessToken = file_get_contents( $url );
|
||||
|
||||
$accessToken = json_decode( $accessToken, true );
|
||||
|
||||
if($accessToken['errcode'] != 0){
|
||||
|
||||
echo json_encode( [ 'code' => 402, 'error' => '获取token失败' ] );
|
||||
|
||||
exit;
|
||||
}
|
||||
$accessToken = $accessToken[ 'access_token' ];
|
||||
|
||||
setCache( $key, $accessToken, 7200, $this->uniacid );
|
||||
}
|
||||
|
||||
return !empty($accessToken)?$accessToken:'';
|
||||
}
|
||||
/**
|
||||
* 功能说明 post 请求
|
||||
*
|
||||
* @param $url
|
||||
* @param $post
|
||||
* @param $method
|
||||
* @param int $header
|
||||
* @return bool|string
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 18:40
|
||||
*/
|
||||
public function curlPost($url,$post=NULL,$post_type='POST'){
|
||||
$result = $this->crulGetData($url,$post,$post_type);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 功能说明 post 请求
|
||||
*
|
||||
* @param $url
|
||||
* @param $post
|
||||
* @param $method
|
||||
* @param int $header
|
||||
* @return bool|string
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-25 18:40
|
||||
*/
|
||||
public function crulGetData($url, $post, $method, $header=1){
|
||||
$this->_errno = NULL;
|
||||
$this->_error = NULL;
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
if($post != NULL)
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
|
||||
curl_setopt($ch, CURLOPT_AUTOREFERER,true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
||||
|
||||
if($header)
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
"Content-Type: application/json; charset=utf-8",
|
||||
)
|
||||
);
|
||||
$result = curl_exec($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $content
|
||||
* @param $access_token
|
||||
* @功能说明: 违禁词检测
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-01-02 17:07
|
||||
*/
|
||||
public function wxContentRlue($content)
|
||||
{
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
|
||||
if(empty($access_token)){
|
||||
|
||||
return ['errcode'=>0];
|
||||
}
|
||||
|
||||
$url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token={$access_token}";
|
||||
$tmp = [
|
||||
'url' => $url,
|
||||
'data' => [
|
||||
'content' => urlencode($content)
|
||||
],
|
||||
];
|
||||
$rest = $this->curlPost($tmp['url'], urldecode(json_encode($tmp['data'])));
|
||||
$rest = json_decode($rest, true);
|
||||
return $rest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $img_path
|
||||
* @功能说明:图片检测
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-03-27 11:44
|
||||
*/
|
||||
function imgSecCheck($img_path){
|
||||
|
||||
//token
|
||||
$access_token = $this->lbSingleGetAccessToken();
|
||||
//地址
|
||||
$url ='https://api.weixin.qq.com/wxa/img_sec_check?access_token='.$access_token;
|
||||
//请求包
|
||||
$post_data = [
|
||||
'media'=>new \CURLFile($img_path)
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL,$url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-03-14 18:56
|
||||
* @功能说明:php二维码 返回base64
|
||||
*/
|
||||
public function phpQrCode($data){
|
||||
|
||||
require_once EXTEND_PATH.'phpqrcode/phpqrcode.php';
|
||||
|
||||
$errorCorrectionLevel = 'L'; //容错级别
|
||||
|
||||
$matrixPointSize = 10;
|
||||
//生成图片大小
|
||||
ob_start();
|
||||
|
||||
\QRcode::png($data,false,$errorCorrectionLevel,$matrixPointSize,2,false,0xFFFFFF,0x000000);
|
||||
|
||||
$imgstr = base64_encode(ob_get_contents());
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
$imgstr = 'data:image/png;base64,'.$imgstr;
|
||||
|
||||
return $imgstr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
235
longbingcore/wxcore/WxTmpl.php
Normal file
235
longbingcore/wxcore/WxTmpl.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class WxTmpl{
|
||||
|
||||
static protected $uniacid;
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
self::$uniacid = $uniacid;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* $data = ['tmpl_name' => '模版名', 'model_name'=> '模块名', 'tid' => 模版消息的标题id, 'kidList' => [4,2,1,3] 模版消息的列表, 'sceneDesc' => '订单支付成功',];
|
||||
* @param $send_data
|
||||
* @功能说明: 添加模版消息
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 14:18
|
||||
*/
|
||||
|
||||
static public function addtmpl ($dis)
|
||||
{
|
||||
//查询数据库里的模版消息
|
||||
$tmpl = Db::name('longbing_card_tmpl_config')->where($dis)->find();
|
||||
//判断数据库里面有没有tmpl_id 没有就生成
|
||||
if(empty($tmpl['tmpl_id'])){
|
||||
//初始化配置模型
|
||||
$service_model = new WxSetting(self::$uniacid);
|
||||
//生成模版消息的参数
|
||||
$send_data = [
|
||||
'tid' => $tmpl['tid'],
|
||||
'kidList' => explode(',',$tmpl['kid']),
|
||||
'sceneDesc' => $tmpl['sceneDesc']
|
||||
];
|
||||
//给客户的小程序添加模版 并返回模版id
|
||||
$tmpl_info = $service_model->addTmpl($send_data);
|
||||
$tmpl_info = json_decode($tmpl_info,true);
|
||||
}else{
|
||||
//有数据就直接返回模版id
|
||||
$tmpl_info['priTmplId'] = $tmpl['tmpl_id'];
|
||||
$tmpl_info['errcode'] = 0;
|
||||
|
||||
}
|
||||
return $tmpl_info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-01-02 11:34
|
||||
* @功能说明:获取模版消息 需要发送的key
|
||||
*/
|
||||
static public function getTmplKey($tmpl_id){
|
||||
|
||||
if(empty($tmpl_id)){
|
||||
return [];
|
||||
}
|
||||
$cach_data = getCache($tmpl_id,self::$uniacid);
|
||||
//如果有缓存直接返回
|
||||
if(!empty($cach_data)){
|
||||
return $cach_data;
|
||||
}
|
||||
//微信库类
|
||||
$service_model = new WxSetting(self::$uniacid);
|
||||
//获取所有模版消息
|
||||
$data = $service_model->getUserTmpl();
|
||||
//没有返回空
|
||||
if(empty($data)){
|
||||
return [];
|
||||
}
|
||||
$data = json_decode($data,true);
|
||||
//如果报错 直接返回
|
||||
if(empty($data['data'])){
|
||||
return [];
|
||||
}
|
||||
$data = $data['data'];
|
||||
//找到该模版id 的模版
|
||||
$found_key = array_search($tmpl_id, array_column($data, 'priTmplId'));
|
||||
|
||||
if(!is_numeric($found_key)){
|
||||
return [];
|
||||
}
|
||||
//获取该模版
|
||||
$tmpl = $data[$found_key];
|
||||
//获取该模版的内容
|
||||
$content = explode('{{',$tmpl['content']);
|
||||
//转换格式
|
||||
foreach ($content as $k =>$value){
|
||||
if($k == 0){
|
||||
unset($content[$k]);
|
||||
continue;
|
||||
}
|
||||
$content[$k] = substr($value,0,strpos($value, '.'));
|
||||
}
|
||||
//存入缓存
|
||||
setCache($tmpl_id,$content,86400,self::$uniacid);
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 15:04
|
||||
* @功能说明:模版参数
|
||||
*/
|
||||
|
||||
static public function tmplParam($key){
|
||||
//订单支付通知
|
||||
$data['pay_order'] = [
|
||||
//标题id
|
||||
'tid' => 1754,
|
||||
//内容的key(暂时不需要)
|
||||
'kidList' => 'thing4,amount2,character_string1,date3',
|
||||
//模版场景类容
|
||||
'sceneDesc' => '订单支付成功',
|
||||
//自动生成模版时内容的顺序
|
||||
'kid' => '4,2,1,3',
|
||||
//模版内容的样板
|
||||
'example' => '物品名称、金额、单号、支付时间',
|
||||
];
|
||||
//订单发货通知
|
||||
$data['send_order'] = [
|
||||
//标题id
|
||||
'tid' => 2414,
|
||||
//内容的key(暂时不需要)
|
||||
'kidList' => '',
|
||||
//模版场景类容
|
||||
'sceneDesc' => '订单发货通知',
|
||||
//自动生成模版时内容的顺序
|
||||
'kid' => '1,2,3,4',
|
||||
//模版内容的样板
|
||||
'example' => '发货时间、订单编号、物流编号、物流公司',
|
||||
];
|
||||
|
||||
//IM 未读私信通知
|
||||
$data['land_order'] = [
|
||||
//标题id
|
||||
'tid' => 585,
|
||||
//内容的key(暂时不需要)
|
||||
'kidList' => '',
|
||||
//模版场景类容
|
||||
'sceneDesc' => '土地订单通知',
|
||||
//自动生成模版时内容的顺序
|
||||
'kid' => '1,2,3,4,5',
|
||||
//模版内容的样板
|
||||
'example' => '订单编号、商品名称、商品详情、订单金额、下单时间',
|
||||
];
|
||||
|
||||
$data['land_over'] = [
|
||||
//标题id
|
||||
'tid' => 30781,
|
||||
//内容的key(暂时不需要)
|
||||
'kidList' => '',
|
||||
//模版场景类容
|
||||
'sceneDesc' => '土地到期提醒',
|
||||
//自动生成模版时内容的顺序
|
||||
'kid' => '1,2,3,4',
|
||||
//模版内容的样板
|
||||
'example' => '土地名称、到期时间、单号、温馨提示',
|
||||
];
|
||||
|
||||
if(key_exists($key,$data)){
|
||||
|
||||
return $data[$key];
|
||||
|
||||
}else{
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $poenid
|
||||
* @param $key_data
|
||||
* @param $send_data
|
||||
* @param $page
|
||||
* @功能说明: 发送模版消息
|
||||
* @author chenniang
|
||||
* @DataTime: 2019-12-26 11:22
|
||||
*/
|
||||
static public function sendTmpl($poenid,$tmpl_id,$send_data,$page){
|
||||
//发送信息内容
|
||||
$data = [
|
||||
//用户openid
|
||||
'touser' => $poenid,
|
||||
//模版id
|
||||
'template_id' => $tmpl_id,
|
||||
//跳转页面
|
||||
'page' => $page,
|
||||
//发送内容
|
||||
'data' => $send_data
|
||||
];
|
||||
//初始化配置模型
|
||||
$service_model = new WxSetting(self::$uniacid);
|
||||
//发送消息
|
||||
$res = $service_model->sendTmpl($data);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @功能说明:转utf 8
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-01-03 19:23
|
||||
*/
|
||||
|
||||
static public function strToUtf8($str){
|
||||
|
||||
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
|
||||
|
||||
if($encode == 'UTF-8'){
|
||||
return $str;
|
||||
}else{
|
||||
return mb_convert_encoding($str, 'UTF-8', $encode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
284
longbingcore/wxcore/YsCloudApi.php
Normal file
284
longbingcore/wxcore/YsCloudApi.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use app\Common\LongbingServiceNotice;
|
||||
|
||||
use app\farm\model\Config;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 达达开放平台sdk
|
||||
* User: 仝帅
|
||||
* Date: 2016-12-19
|
||||
* Time: 16:48
|
||||
*/
|
||||
class YsCloudApi
|
||||
{
|
||||
|
||||
protected $appId;
|
||||
|
||||
protected $appKey;
|
||||
|
||||
protected $signature;
|
||||
|
||||
protected $url;
|
||||
|
||||
protected $uniacid;
|
||||
|
||||
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
$this->uniacid= $uniacid;
|
||||
|
||||
$config_model = new Config();
|
||||
|
||||
$config = $config_model->dataInfo(['uniacid'=>$uniacid]);
|
||||
|
||||
$this->AppKey = $config['ys_appkey'];
|
||||
|
||||
$this->Secret = $config['ys_secret'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:42
|
||||
* @功能说明:获取令牌
|
||||
*/
|
||||
|
||||
public function getToken(){
|
||||
|
||||
$url = 'https://open.ys7.com/api/lapp/token/get';
|
||||
|
||||
$key = 'yscloud_token';
|
||||
|
||||
$token = getCache($key,$this->uniacid);
|
||||
|
||||
$post_data = [
|
||||
|
||||
'appKey' => $this->AppKey,
|
||||
|
||||
'appSecret' => $this->Secret
|
||||
];
|
||||
|
||||
if(empty($token)){
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
if(!empty($data['code'])&&$data['code']==200){
|
||||
|
||||
$token = $data['data']['accessToken'];
|
||||
|
||||
setCache($key,$token,86400*6,$this->uniacid);
|
||||
|
||||
}else{
|
||||
|
||||
$token = '';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:54
|
||||
* @功能说明:获取空间列表
|
||||
*/
|
||||
public function getVideoList(){
|
||||
|
||||
$url = 'https://open.ys7.com/api/lapp/live/video/list';
|
||||
|
||||
$post_data = [
|
||||
|
||||
'accessToken' => $this->getToken(),
|
||||
|
||||
'pageSize' => 100
|
||||
];
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-02-17 17:57
|
||||
* @功能说明:获取空间详情
|
||||
*/
|
||||
public function getVideoInfo($deviceSerial,$channelNo=1){
|
||||
|
||||
$url = 'https://open.ys7.com/api/lapp/v2/live/address/get';
|
||||
|
||||
$key = $deviceSerial.'-2'.$channelNo;
|
||||
|
||||
$url_data = getCache($key,$this->uniacid);
|
||||
|
||||
if(empty($url_data)){
|
||||
|
||||
$post_data = [
|
||||
|
||||
'accessToken' => $this->getToken(),
|
||||
|
||||
'deviceSerial'=> $deviceSerial,
|
||||
|
||||
'channelNo' => $channelNo,
|
||||
|
||||
'protocol' => 2,
|
||||
|
||||
'quality' => 2
|
||||
];
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = @json_decode($data,true);
|
||||
|
||||
if(isset($data['code'])&&$data['code']==200){
|
||||
|
||||
$url_data = $data['data']['url'];
|
||||
|
||||
setCache($key,$url_data,86400,$this->uniacid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $url_data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $deviceSerial
|
||||
* @param $direction
|
||||
* @param int $channelNo
|
||||
* @功能说明:开始转动
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-04-12 10:51
|
||||
*/
|
||||
public function startTurn($deviceSerial,$direction,$channelNo=1)
|
||||
{
|
||||
$url='https://open.ys7.com/api/lapp/device/ptz/start';
|
||||
|
||||
$post_data = [
|
||||
|
||||
'accessToken' => $this->getToken(),
|
||||
|
||||
'deviceSerial'=> $deviceSerial,
|
||||
|
||||
'channelNo' => $channelNo,
|
||||
|
||||
'direction' => $direction,
|
||||
|
||||
'speed' => 1
|
||||
];
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $deviceSerial
|
||||
* @param $direction
|
||||
* @param int $channelNo
|
||||
* @功能说明:停止转动
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-04-12 10:51
|
||||
*/
|
||||
public function stopTurn($deviceSerial,$direction=0,$channelNo=1)
|
||||
{
|
||||
$url='https://open.ys7.com/api/lapp/device/ptz/stop';
|
||||
|
||||
$post_data = [
|
||||
|
||||
'accessToken' => $this->getToken(),
|
||||
|
||||
'deviceSerial'=> $deviceSerial,
|
||||
|
||||
'channelNo' => $channelNo,
|
||||
|
||||
'direction' => $direction,
|
||||
|
||||
];
|
||||
|
||||
$data = lbCurlPost($url,$post_data);
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param $post_data
|
||||
* @param string $post_type
|
||||
* @功能说明:发送请求
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-10-26 14:38
|
||||
*/
|
||||
public function request($url,$post_data,$post_type='POST'){
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
$post_data = json_encode($post_data);
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => $post_type,
|
||||
CURLOPT_POSTFIELDS => $post_data,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Content-Type:application/json",
|
||||
"User-Agent:openApi",
|
||||
"Content-Type:application/json; charset=utf-8",
|
||||
"accept-encoding:gzip,deflate",
|
||||
"time-stamp:".time(),
|
||||
// "data-signature:D2C3D3C7289EAE111277999D21196D4D",
|
||||
"data-signature:".strtoupper(md5($this->appKey.$post_data))
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
return json_decode($response,true);
|
||||
|
||||
// if ($err) {
|
||||
// echo "cURL Error #:" . $err;
|
||||
// } else {
|
||||
// echo $response;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user