init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)

这个提交包含在:
Developer
2026-10-30 10:18:50 +08:00
当前提交 1f3e0ce2f6
共有 9291 个文件被更改,包括 1776674 次插入 和 0 次删除

查看文件

@@ -0,0 +1,228 @@
<?php
namespace Addons\Api;
//[1.3.89]
/**
* 菜鸟物流云
* Class CNLogistics
* @package Addons\Api
*/
class CNLogistics
{
private $appKey;
private $appSecret;//菜鸟AppSecret
private $logisticProviderId;//token(申请成功后菜鸟给的token)
private $cpCode;// 物流编号 - YTO
/**
* 初始化配置
* CNLogistics constructor.
* @param $token 授权token
* @param string $cp_code 物流编号
*/
public function __construct($token, $cp_code = '')
{
$this->logisticProviderId = $token;
$this->cpCode = $cp_code;
$this->appKey = C('CN_APP_KEY');
$this->appSecret = C('CN_APP_SECRET');
}
/**
* 获取发货地,CP开通状态,账户的使用情况
* @return bool|string
*/
public function getMerInfo()
{
$type = 'TMS_WAYBILL_SUBSCRIPTION_QUERY';
$requestData = array(
'cpCode' => $this->cpCode,
);
$res = $this->sendRequest($requestData, $type);
return $res;
}
/**
* 电子面单取号接口
* @param array $sender 发货人信息
* @param array $recipient 收货人信息
* @param null $orderCode 订单号(能重复)
* @return mixed
*/
public function getExpressCode($sender = array(), $recipient = array(), $orderCode = null)
{
/**
* - orderCode不能重复
* - recipient数据必须与为“TMS_WAYBILL_SUBSCRIPTION_QUERY”获取数据
* - 发货人/收货人,地址/联系人/联系方式不能为空
*/
// 请求方式
$type = "TMS_WAYBILL_GET";
//请求内容
$requestData = array(
'cpCode' => $this->cpCode,
'sender' => array(
'address' => array(
'city' => $sender['city'],
'detail' => $sender['detail'],//true
'district' => $sender['district'],
'province' => $sender['province'],//true
'town' => $sender['town'],
),
'mobile' => $sender['mobile'],
'name' => $sender['name'],//true
'phone' => $sender['phone'],
),
'tradeOrderInfoDtos' => array(
'tradeOrderInfoDto' => array(
'logisticsServices' => '',
'objectId' => $orderCode,
'orderInfo' => array(
'orderChannelsType' => 'OTHERS',//订单渠道平台,请按实际订单所属平台传入(详见https://support-cnkuaidi.taobao.com/doc.htm#?docId=105085&docType=1)
'tradeOrderList' => array(
0 => $orderCode,
),//订单号列表(上限100个)
),
'packageInfo' => array(
'id' => $orderCode,
'items' => array(
0 => array(
'count' => intval($sender['goods_count']),
'name' => $sender['goods_name'],
),
),
'volume' => $sender['goods_volume'],//体积, 单位 ml
'weight' => $sender['goods_weight'],//重量,单位 g
),//包裹信息
'recipient' => array(
'address' => array(
'city' => $recipient['city'],
'detail' => $recipient['detail'],
'district' => $recipient['district'],
'province' => $recipient['province'],
'town' => $recipient['town'],
),
'mobile' => $recipient['mobile'],
'name' => $recipient['name'],
'phone' => $recipient['phone'],
),//收货人信息
'templateUrl' => $sender['template_url'],
'userId' => $sender['user_id'],
),
),
'storeCode' => '无',
'resourceCode' => '无',
'dmsSorting' => 'false',
'needEncrypt' => 'false',
);
// print_r($requestData);
// exit;
$res = $this->sendRequest($requestData, $type);
return $res;
}
/**
* 电子面单取消
* @param $waybillCode 电子面单号
* @return mixed
*/
public function cancelExpress($waybillCode)
{
$type = 'TMS_WAYBILL_DISCARD';
$requestData = array(
'cpCode' => $this->cpCode,
'waybillCode' => $waybillCode,
);
$res = $this->sendRequest($requestData, $type);
return $res;
}
/**
* 获取云打印标准面单
* @return bool|string
*/
public function getStandardTemplates()
{
$type = 'CLOUDPRINT_STANDARD_TEMPLATES';
$requestData = array(
'cpCode' => $this->cpCode,
);
$res = $this->sendRequest($requestData, $type);
return $res;
}
/**
* 获取云打印ISV模板
* @return bool|string
*/
public function getISVTemplates()
{
$type = 'CLOUDPRINT_ISV_TEMPLATES';
$requestData = array(
'cpCode' => $this->cpCode,
'templateType' => 6,
);
$res = $this->sendRequest($requestData, $type);
return $res;
}
/**
* 获取商家自定义区列表
*/
public function getMerCustomAreas()
{
$type = 'CLOUDPRINT_SELLER_CUSTOM_AREAS';
$requestData = array();
$res = $this->sendRequest($requestData, $type);
return $res;
}
/**
* 发送请求
* @param $requestData 请求报文内容
* @param $type 消息类型
* @return bool|string
*/
public function sendRequest($requestData, $type)
{
$request_url = 'http://link.cainiao.com/gateway/link.do';//正式环境
$requestData = json_encode($requestData);//正式环境
$get_data = array(
"logistic_provider_id={$this->logisticProviderId}",
"msg_type={$type}",
"logistics_interface={$requestData}",
"data_digest={$this->createSign($requestData)}",
);
$get_data = implode('&', $get_data);
// print_r($get_data);
$res = http_request($request_url, $get_data);
if ($res) {
$res = json_decode($res, true);
if ($res['success'] == 'true') {
$res['status'] = 1;
$res['msg'] = '成功';
} else {
$res['status'] = 0;
$res['msg'] = $res['errorMsg'] ? $res['errorMsg'] : '失败';
}
} else {
$res = array(
'status' => 0,
'msg' => '请求错误',
);
}
return $res;
}
/**
* 电商Sign签名生成
* @param data 内容
* @param appkey Appkey
* @return DataSign签名
*/
private function createSign($data)
{
return urlencode(base64_encode(md5($data . $this->appSecret, true)));
}
}

查看文件

@@ -0,0 +1,66 @@
<?php
namespace Addons\Api;
class Crypto{
/**
* 数据加密
* @param unknown $data 原始数据
* @param unknown $key 密钥
* @return string 加密数据
*/
function encrypt($data, $key)
{
$key = md5($key);
$x = 0;
$len = strlen($data);
$l = strlen($key);
for ($i = 0; $i < $len; $i++)
{
if ($x == $l)
{
$x = 0;
}
$char .= $key{$x};
$x++;
}
for ($i = 0; $i < $len; $i++)
{
$str .= chr(ord($data{$i}) + (ord($char{$i})) % 256);
}
return base64_encode($str);
}
/**
* 数据解密
* @param unknown $data 密文
* @param unknown $key 加密密钥
* @return string 原文
*/
function decrypt($data, $key)
{
$key = md5($key);
$x = 0;
$data = base64_decode($data);
$len = strlen($data);
$l = strlen($key);
for ($i = 0; $i < $len; $i++)
{
if ($x == $l)
{
$x = 0;
}
$char .= substr($key, $x, 1);
$x++;
}
for ($i = 0; $i < $len; $i++)
{
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1)))
{
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
}
else
{
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
return $str;
}
}

查看文件

@@ -0,0 +1,49 @@
<?php
namespace Addons\Api;
use Addons\Api\ResultCodeManager;
//[1.4.13]
class GlobalFunction
{
public static function buildResult($code, $msg, $data = [])
{
$result = [];
$result['code'] = $code;
$result['msg'] = $msg;
$result['data'] = $data;
return $result;
}
//封装验证参数是否定义 $array 参数数组 $type 请求方式 (get or post)参数数组
public static function checkParams($array, $type)
{
$data = [
'status' => 0,
'result' => "success",
];
foreach ($array as $val) {
if (!array_key_exists($val, $type)) {
$result = self::buildResult(ResultCodeManager::MISS_REQUIRED_PARAM, str_replace('%PARAM%', $val, ResultCodeManager::$messages[ResultCodeManager::MISS_REQUIRED_PARAM]));
$data = [
'status' => 1,
'result' => $result,
];
}
}
return $data;
}
public static function file_dress()
{
$filePath = dirname(dirname(__DIR__));
return $filePath;
}
}

查看文件

@@ -0,0 +1,29 @@
<?php
namespace Addons\Api;
//[1.5.37]
/**
* 处理门店结算账单、其他金额统计
* Class HandleStoreSettled
* @package Addons\Api
*/
class HandleStoreSettled
{
public function handlePrice($store_id, $start_time, $end_time)
{
$money = 0;
$item = array(
'store_id' => $store_id,
'start_time' => $start_time,
'end_time' => $end_time,
'money' => $money,
);
\Think\Hook::listen('store_settled_distribution', $item);//分销结算金额
/**
* ...其他预留
*/
return $item['money'];
}
}

查看文件

@@ -0,0 +1,910 @@
<?php
namespace Addons\Api;
use Common\Model\AppInfoModel;
use Common\Model\AppweixinModel;
use Common\Model\MiniProgramAuthModel;
use Common\Model\MiniProgramExamineModel;
use Common\Model\MiniProgramUseModel;
use Common\Model\WxappinfoModel;
//[1.8.73]
/**
* 商城小程序API
* Class MerXcxConf
* @package Addons\Api
*/
class MerXcxConf
{
private $merchant_id; //商户id
public $errMsg; //错误描述
public function __construct($merchant_id)
{
$this->merchant_id = $merchant_id;
}
/**
* 获取基本信息
*/
public function getBaseData()
{
$AppInfoModel = new WxappinfoModel(); //商户正在使用的小程序
$map = array(
'merchant_id' => $this->merchant_id
);
$appInfo = $AppInfoModel->getFind($map); //获取小程序信息
$examine = array();
$new_version = 0;
if (!empty($appInfo)) {
$examine = $this->getExamineState(); //获取小程序当前审核状态
$this->modifyDomain(); //设置小程序域名
}
$AppWeiXinModel = new AppweixinModel();
$wxInfo = $AppWeiXinModel->getFind(array('id' => 1));
$version_name = array(
'1' => 'default_version_id',
'2' => 'diy_version_id',
'3' => 'default_live_version_id',
'4' => 'diy_live_version_id',
); // 1普通版(无直播) 2diy版(无直播) 3普通版(有直播) 4diy版(有直播)
$open_count = 0;
$preview_code_model = 1;
if ($wxInfo['diy_live_version_id']) {
$open_count++;
$preview_code_model = 4;
}
if ($wxInfo['default_live_version_id']) {
$open_count++;
$preview_code_model = 3;
}
if ($wxInfo['diy_version_id']) {
$open_count++;
$preview_code_model = 2;
}
if ($wxInfo['default_version_id']) {
$open_count++;
$preview_code_model = 1;
}
if (!empty($appInfo) && !empty($examine) && $examine['status'] == 4) {
//判断是否有新版本可更新
$this_version = $wxInfo[$version_name[$examine['model_type']]];
$preview_code_model = intval($examine['model_type']);
if ($examine['template_id'] != $this_version) {
$new_version = 1;
}
} else if (!empty($examine)) {
$preview_code_model = intval($examine['model_type']);
}
return array(
'status' => 1,
'msg' => '获取成功',
'data' => array(
'preview_code_model' => $preview_code_model,
'authData' => $appInfo ? $appInfo : array(),
'examine' => $examine,
'new_version' => $new_version,
'open_default' => $wxInfo['default_version_id'] > 0 ? true : false,
'open_diy' => $wxInfo['diy_version_id'] > 0 ? true : false,
'open_default_live' => $wxInfo['default_live_version_id'] > 0 ? true : false,
'open_diy_live' => $wxInfo['diy_live_version_id'] > 0 ? true : false,
'open_count' => $open_count,
'online_status' => intval($appInfo['online_status'])
),
);
}
/**
* 获取充值入口显示状态
*/
public function changeOnlineStatus()
{
$AppInfoModel = new WxappinfoModel(); //商户正在使用的小程序
$map = array(
'merchant_id' => $this->merchant_id
);
$online_status = I('post.online_status');
$appInfo = $AppInfoModel->updateOrder($map, array('online_status' => $online_status)); //获取小程序信息
if ($appInfo) {
return array(
'status' => 1,
'msg' => '修改成功',
);
} else {
return array(
'status' => 0,
'msg' => '修改失败',
);
}
}
/**
* 获取小程序体验二维码
*/
public function getPreviewQrImg()
{
$AppWeiXinModel = new AppweixinModel();
$template_info = $AppWeiXinModel->getFind(array('id' => 1));
if (!$template_info) {
return array(
'status' => 0,
'msg' => '系统暂未设置商城小程序模板'
);
}
$this->setWebView();
//模板id
$model = I('post.model') ? I('post.model') : 1; //1普通版(无直播) 2diy版(无直播) 3普通版(有直播) 4diy版(有直播)
$version_name = array(
'1' => 'default_version_id',
'2' => 'diy_version_id',
'3' => 'default_live_version_id',
'4' => 'diy_live_version_id',
);
$template_id = $template_info[$version_name[$model]];
$map = array(
'merchant_id' => $this->merchant_id,
);
//获取第三方授权的access_token
$access_token = get_authorizer_access_tokens($this->merchant_id);
$WxAppInfoModel = new WxappinfoModel();
$extAppid = $WxAppInfoModel->getFindField($map, 'authorizer_appid');
$merchant_id_text = "merchant_id";
$server = 'https://' . $template_info['server'] . "/index.php/SmallProgramApi"; //正式
$domain = 'https://' . $template_info['server'] . "/index.php"; //正式
// $server = 'http://' . $template_info['server'] . "/index.php/SmallProgramApi";//线下测试
if ($model == 3 || $model == 4) {
//有直播版
$data = array(
'template_id' => $template_id,
"user_version" => "V" . $template_id,
'ext_json' => "{
\"extEnable\":true,
\"extAppid\": \"$extAppid\",
\"ext\":{\"siteBaseUrl\":\"$server\",\"domain\":\"$domain\",\"appid\":\"$extAppid\",\"$merchant_id_text\":\"$this->merchant_id\"},
\"plugins\": {\"live-player-plugin\":{\"version\": \"1.2.6\",\"provider\": \"wx2b03c6e691cd7370\"},\"sendCoupon\": {
\"version\": \"1.1.7\",
\"provider\": \"wxf3f436ba9bd4be7b\"
}}
}",
"user_desc" => $template_info['information'],
);
} else if ($model == 1 || $model == 2) {
//无直播版
$data = array(
'template_id' => $template_id,
"user_version" => "V" . $template_id,
'ext_json' => "{
\"extEnable\":true,
\"extAppid\": \"$extAppid\",
\"ext\":{\"siteBaseUrl\":\"$server\",\"domain\":\"$domain\",\"appid\":\"$extAppid\",\"$merchant_id_text\":\"$this->merchant_id\"},
\"plugins\": {\"sendCoupon\": {
\"version\": \"1.1.7\",
\"provider\": \"wxf3f436ba9bd4be7b\"
}}
}",
"user_desc" => $template_info['information'],
);
} else {
return array(
'status' => 0,
'msg' => '请求参数有误',
);
}
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
$url = "https://api.weixin.qq.com/wxa/commit?access_token=" . $access_token;
$response = curl_get($url, $data);
$result = json_decode($response, true);
if ($result["errcode"] == 0 && $result["errmsg"] == "ok") {
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = "https://api.weixin.qq.com/wxa/get_qrcode?access_token=" . $access_token;
$data = curl_getm($url);
$path = "./Uploads/App/Code/" . $this->merchant_id;
if (!is_dir($path)) {
if (!is_dir('./Uploads/App')) {
mkdir("./Uploads/App", 0777);
}
if (!is_dir('./Uploads/App/Code')) {
mkdir("./Uploads/App/Code", 0777);
}
mkdir("./Uploads/App/Code/" . $this->merchant_id, 0777);
} else {
$p = scandir($path);
foreach ($p as $val) {
if ($val != "." && $val != "..") {
unlink($path . '/' . $val);
}
}
}
$file_name = $path . '/' . rand(1000, 9999) . 'qrcode.jpg';
if (file_put_contents($file_name, $data)) {
return array(
'status' => 1,
'msg' => '获取成功',
'preview_path' => substr($file_name, 1),
);
}
} else {
return array(
'status' => 0,
'msg' => $result["errmsg"]
);
}
}
/**
* 设置小程序用户隐私保护指引
*/
public function setPrivacySetting(){
$data = array(
'privacy_ver' => 2,
'setting_list' => array(
array(
"privacy_key" => 'Location',
"privacy_text" => '获取离您最近的门店'
),
array(
"privacy_key" => 'AlbumWriteOnly',
"privacy_text" => '保存图片或者上传图片'
),
array(
"privacy_key" => 'PhoneNumber',
"privacy_text" => '在必要时和用户联系'
),
array(
"privacy_key" => 'UserInfo',
"privacy_text" => '分辨用户'
)
),
'owner_setting' => array(
'contact_phone' => '18778995730',
'notice_method' => '通过公告联系'
)
);
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = 'https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=' . $access_token;
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
$response = curl_get($url, $data);
$response = json_decode($response, true);
return $response;
}
/**
* 检查小程序审核状态
* @return mixed
*/
public function getExamineState()
{
$MiniProgramExamineModel = new MiniProgramExamineModel();
$map = array(
'merchant_id' => $this->merchant_id,
'state' => 1,
);
$history = $MiniProgramExamineModel->getFind($map, '*', 'id desc');
if (!empty($history)) {
if ($history['status'] == 2) {
$access_token = get_authorizer_access_tokens($this->merchant_id);
if (!empty($history['audit_id'])) {
$requestData = array(
'auditid' => $history['audit_id'],
);
$url = "https://api.weixin.qq.com/wxa/get_auditstatus?access_token=" . $access_token;
$response = http_request($url, json_encode($requestData));
} else {
$url = "https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=" . $access_token;
$response = curl_getm($url);
}
$response = json_decode($response, true);
//审核状态 0审核通过 1审核驳回 2审核中 3撤回审核 4发布成功
if ($response['errcode'] == '0' && $history['status'] != $response['status']) {
$save = array(
'status' => $response['status'],
);
$history['status'] = $response['status'];
if ($response['status'] == 1) {
$reason = str_replace(array("\r\n", "\r", "\n", "<br>"), "", $response["reason"]);
$save['reject_msg'] = $reason;
$history['reject_msg'] = $reason;
}
if (empty($history['audit_id'])) {
$save['audit_id'] = $response['auditid'];
}
$MiniProgramExamineModel->updateOrder(array('id' => $history['id']), $save);
}
}
} else {
$history = array();
}
return $history;
}
/**
* 域名参数设置 小程序模板开发设置安全域名
*/
public function modifyDomain()
{
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = "https://api.weixin.qq.com/wxa/modify_domain?access_token=" . $access_token;
$AppWeiXinModel = new AppweixinModel();
$cache = $AppWeiXinModel->getFind(array('id' => 1));
$data = array(
"action" => "add",
"requestdomain" => array("https://" . $cache['server']),
"wsrequestdomain" => array("wss://" . $cache['server'] . ":7282"),
"uploaddomain" => array("https://" . $cache['server']),
"downloaddomain" => array("https://" . $cache['server']),
);
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
$response = curl_get($url, $data);
$result = json_decode($response, true);
}
/**
* 小程序的授权功能 准备跳转授权页面
* @param $redirect_url
* @return string
*/
public function authIndex($redirect_url)
{
$AppWeiXinModel = new AppweixinModel();
$appid = $AppWeiXinModel->getFindField(array('id' => 1), 'appid');
$access = get_acc_token();
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=' . $access;
$data = array(
'component_appid' => $appid
);
$postData = json_encode($data);
$response = curl_get($url, $postData);
$result = json_decode($response, true);
$save = array(
'component_access_token' => $access,
'pre_auth_code' => $result['pre_auth_code']
);
$AppWeiXinModel->updateOrder(array('id' => 1), $save); //保存到数据库
//点击授权
$pre_auth_code = $result['pre_auth_code'];
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
|| (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$redirect_uri = $http_type . C("adminhttp") . '/index.php/' . $redirect_url . '/merchant_id/' . $this->merchant_id;
$urls = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=' . $appid . '&auth_type=2&pre_auth_code=' . $pre_auth_code . '&redirect_uri=' . $redirect_uri;
return $urls;
}
/**
* 小程序授权回调处理
* @return bool
*/
public function authSuccess()
{
//这个方法是参看授权状态并且提交授权信息的
$AppWeiXinModel = new AppweixinModel();
$wxInfo = $AppWeiXinModel->getFind(array('id' => 1));
if ($_GET['auth_code']) {
$appid = $wxInfo['appid'];
$access = get_acc_token();
//获取第三方接口调用凭据
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=' . $access;
$data = array(
'component_appid' => $appid,
'authorization_code' => $_GET['auth_code']
);
$data = json_encode($data);
$response = curl_get($url, $data);
$result = json_decode($response, true);
$access = false;
foreach ($result['authorization_info']['func_info'] as $val) {
if ($val["funcscope_category"]["id"] == 18) {
$access = true;
break;
}
}
if (!$access) {
$this->errMsg = '该小程序没有开发管理权限,登录小程序后台清除所有第三方授权,然后重新授权';
return false;
}
$authorizer_appid = $result['authorization_info']['authorizer_appid'];
$item = $this->get_authorizer_info($authorizer_appid); //获取小程序详细信息
$item['authorizer_appid'] = $authorizer_appid;
$item['authorizer_access_token'] = $result['authorization_info']['authorizer_access_token'];
$item['authorizer_refresh_token'] = $result['authorization_info']['authorizer_refresh_token'];
$item['access_token_time'] = time();
$AppInfoModel = new WxappinfoModel();
//小程序绑定验重
$repeatMap = [
'authorizer_appid' => $item['authorizer_appid'],
'merchant_id' => ['neq', $this->merchant_id],
];
$repeat = $AppInfoModel->getFind($repeatMap);
if ($repeat) {
$this->errMsg = '该系统已有商户使用该小程序,请更换其他小程序';
return false;
}
$map = array(
'merchant_id' => $this->merchant_id
);
// 判断当前用户是否授权或者设置过授权信息
$appInfo = $AppInfoModel->getFind($map);
if (empty($appInfo)) {
//添加一个小程序的配置信息
$item['merchant_id'] = $this->merchant_id;
$AppInfoModel->addOrder($item);
} else {
$AppInfoModel->updateOrder($map, $item);
}
$ProgramAuthModel = new MiniProgramAuthModel();
$aMap = array(
'merchant_id' => $this->merchant_id,
'status' => 1,
);
$ProgramAuthModel->updateOrder($aMap, array('status' => 0)); //把之前的授权记录改为不启用
$aItem = array(
'merchant_id' => $this->merchant_id,
'status' => 1,
'appid' => $item['authorizer_appid'],
'add_time' => time(),
'program_name' => $item['nick_name'],
'operator_id' => session('jurisdiction_user')['id'],
);
$add = $ProgramAuthModel->addOrder($aItem); //新增一条授权记录
if (!empty($appInfo) && $appInfo['authorizer_appid'] != $item['authorizer_appid']) {
//授权的是新的小程序
$MiniProgramExamineModel = new MiniProgramExamineModel();
$mMap = array(
'merchant_id' => $this->merchant_id,
'id' => array('neq', $add),
'state' => 1
);
$MiniProgramExamineModel->updateOrder($mMap, array('state' => 0)); //把之前的审核中的记录状态改为旧版
}
return true;
} else {
$this->errMsg = '系统暂未添加商城小程序';
return false;
}
}
/**
* 获取小程序的详情信息
*/
public function get_authorizer_info($authorizer_appid)
{
$AppWeiXinModel = new AppweixinModel();
$appid = $AppWeiXinModel->getFindField(array('id' => 1), 'appid');
$access = get_acc_token();
// 获取授权方的账号基本信息
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=' . $access;
$data = array(
'component_appid' => $appid,
'authorizer_appid' => $authorizer_appid
);
$data = json_encode($data);
$response = curl_get($url, $data);
$result = json_decode($response, true);
// 插入数据库
$info['nick_name'] = $result['authorizer_info']['nick_name'];
$info['head_img'] = $result['authorizer_info']['head_img'];
$info['service_type_info'] = $result['authorizer_info']['service_type_info']['id'];
$info['user_name'] = $result['authorizer_info']['user_name'];
$info['signature'] = $result['authorizer_info']['signature'];
$info['principal_name'] = $result['authorizer_info']['principal_name'];
$info['qrcode_url'] = $result['authorizer_info']['qrcode_url'];
return $info;
}
/**
* 小程序提交审核
* @param int $urgent_state 0不加急 1加急审核
* @return array
*/
public function submitAudit($urgent_state = 0)
{
$model = I('post.model') ? I('post.model') : 1; //1普通版(无直播) 2diy版(无直播) 3普通版(有直播) 4diy版(有直播)
$setPreview = $this->getPreviewQrImg();
if ($setPreview['status'] == 0) {
return $setPreview;
}
$this->setWebView(); //设置小程序web-view域名
$AppWeiXinModel = new AppweixinModel();
$field = array(
'default_version_id',
'diy_version_id',
'default_live_version_id',
'diy_live_version_id',
);
$app = $AppWeiXinModel->getFind(array('id' => 1), $field);
$version_name = array(
'1' => 'default_version_id',
'2' => 'diy_version_id',
'3' => 'default_live_version_id',
'4' => 'diy_live_version_id',
);
$template_id = $app[$version_name[$model]];
$tags = $app['tag'];
$appPage = $this->getPage(); //获取配置页面
if ($appPage['status'] != 1) {
return $appPage;
}
$address = $appPage['page_list'];
$appCategory = $this->getCategory();
if ($appCategory['status'] != 1) {
return $appCategory;
}
$categoryList = $appCategory['category_list'];
if (count($categoryList) > 1) {
$data = array(
'item_list' => array(
array(
"address" => $address[0],
"tag" => $tags,
"first_class" => $categoryList[0]['first_class'],
"second_class" => $categoryList[0]['second_class'],
"first_id" => $categoryList[0]['first_id'],
"second_id" => $categoryList[0]['second_id'],
"title" => "首页"
), array(
"address" => $address[1],
"tag" => $tags,
"first_class" => $categoryList[1]['first_class'],
"second_class" => $categoryList[1]['second_class'],
"first_id" => $categoryList[1]['first_id'],
"second_id" => $categoryList[1]['second_id'],
"title" => "功能页面"
),
),
'order_path' => 'pages/myOrder/myOrder'
);
} else {
$data = array(
'item_list' => array(
array(
"address" => $address[0],
"tag" => $tags,
"first_class" => $categoryList[0]['first_class'],
"second_class" => $categoryList[0]['second_class'],
"first_id" => $categoryList[0]['first_id'],
"second_id" => $categoryList[0]['second_id'],
"title" => "首页"
)
),
'order_path' => 'pages/myOrder/myOrder'
);
}
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = 'https://api.weixin.qq.com/wxa/submit_audit?access_token=' . $access_token;
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
$response = curl_get($url, $data);
$response = json_decode($response, true);
// 如果提交成功插入数据 跳转页面
if ($response['errmsg'] == "ok" || $response["errcode"] == 85009) {
//数据库插入一条提交审核记录
//获取版本信息
$MiniProgramUseModel = new MiniProgramUseModel();
$uMap = array(
'template_id' => $template_id,
'type' => $model,
);
$versionInfo = $MiniProgramUseModel->getOrderFind($uMap, '*', 'id desc');
if (empty($versionInfo)) {
$access_token = get_acc_token();
$url = "https://api.weixin.qq.com/wxa/gettemplatelist?access_token=" . $access_token;
$responses = curl_get($url);
$results = json_decode($responses, true);
foreach ($results['template_list'] as $v) {
if ($template_id == $v['template_id']) {
$user_version = $v['user_version'];
$user_desc = $v['user_desc'];
break;
}
}
} else {
$user_version = $versionInfo['user_version'];
$user_desc = $versionInfo['user_desc'];
}
$aMap = array(
'merchant_id' => $this->merchant_id
);
$AppInfoModel = new WxappinfoModel();
$appInfo = $AppInfoModel->getFind($aMap);
$history = array(
'merchant_id' => $this->merchant_id,
'version_info' => $user_desc,
'version' => $user_version,
'template_id' => $template_id,
'program_name' => $appInfo['nick_name'],
'appid' => $appInfo['authorizer_appid'],
'audit_id' => $response['auditid'],
'add_time' => time(),
'status' => 2,
'state' => 1,
'submit_operator_id' => session('jurisdiction_user')['id'],
'model_type' => $model,
);
$MiniProgramExamineModel = new MiniProgramExamineModel();
$MiniProgramExamineModel->updateOrder(array('merchant_id' => $this->merchant_id), array('state' => 0)); //把之前的审核中的记录状态改为旧版
$add = $MiniProgramExamineModel->addOrder($history); //新增提交审核记录
$history['id'] = $add;
if ($urgent_state == 1) {
//加急审核
$res = $this->sendUrgentAudit($history['id'], $history['audit_id']);
if ($res['status'] == 1) {
$msg = '提交审核成功';
} else {
$msg = '版本审核提交成功,加急审核提交失败';
}
return array(
'msg' => $msg,
'status' => 1,
'data' => $history,
'res' => $res,
);
} else {
return array(
'msg' => '提交审核成功',
'status' => 1,
'data' => $history,
);
}
} else {
return array(
'msg' => $response['errmsg'],
'status' => 0,
'data' => $response
);
}
}
/**
* 提交加急审核请求
* @param $examine_id 审核记录id
* @param $audit_id 微信官方审核单id
* @return mixed
*/
public function sendUrgentAudit($examine_id, $audit_id)
{
$requestData = array(
'auditid' => $audit_id,
);
$access_token = get_acc_token();
$url = "https://api.weixin.qq.com/wxa/speedupaudit?access_token=" . $access_token;
$response = http_request($url, json_encode($requestData));
$response = json_decode($response, true);
if ($response['errcode'] == '0') {
$save = array(
'urgent_audit' => 1,
);
$MiniProgramExamineModel = new MiniProgramExamineModel();
$MiniProgramExamineModel->updateOrder(array('id' => $examine_id), $save);
$res['status'] = 1;
$res['msg'] = '加急审核提交成功';
} else {
$res['status'] = 0;
$res['msg'] = $response['errmsg'] ? $response['errmsg'] : '请求发生错误';
$res['data'] = $response;
}
return $res;
}
/**
* 设置小程序web-view域名
*/
public function setWebView()
{
$access_token = get_authorizer_access_tokens($this->merchant_id, 1);
$url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=" . $access_token;
$data['action'] = "add";
$data['webviewdomain'] = array("https://" . C("adminhttp"));
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
$response = curl_get($url, $data);
}
/**
* 获取配置页面
*/
public function getPage()
{
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = "https://api.weixin.qq.com/wxa/get_page?access_token=" . $access_token;
$data = curl_getm($url);
//显示获得的数据
$data = json_decode($data, true);
if ($data['errmsg'] == "ok") {
return array(
'status' => 1,
'page_list' => $data['page_list'],
);
} else {
return array(
'status' => 0,
'msg' => "获取小程序的第三方提交代码的页面配置接口错误:" . $data['errmsg'],
);
}
}
/**
* 获取小程序的授权目录
* @return array
*/
public function getCategory()
{
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = "https://api.weixin.qq.com/wxa/get_category?access_token=" . $access_token;
$data = curl_getm($url);
//显示获得的数据
$data = json_decode($data, true);
if ($data['errmsg'] == "ok") {
return array(
'status' => 1,
'category_list' => $data['category_list']
);
} else {
return array(
'status' => 0,
'msg' => "获取授权小程序帐号的可选类目:" . $data['errmsg']
);
}
}
/**
* 绑定开发体验用户
*/
public function bindUser()
{
$id = I('post.id');
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = "https://api.weixin.qq.com/wxa/bind_tester?access_token=" . $access_token;
$data = array(
'wechatid' => $id,
);
$data = json_encode($data);
$response = curl_get($url, $data);
$response = json_decode($response, true);
if ($response['errcode'] == 0) {
$res['status'] = 1;
$res['msg'] = "添加成功";
} else {
$res['status'] = 0;
$res['msg'] = "添加失败,请检查微信号是否正常";
$res['data'] = $response;
}
return $res;
}
/**
* 小程序审核撤回
*/
public function undoCodeAudit()
{
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = "https://api.weixin.qq.com/wxa/undocodeaudit?access_token=" . $access_token;
$response = curl_getm($url);
$response = json_decode($response, true);
if ($response['errcode'] == 0) {
$res['status'] = 1;
$res['msg'] = "审核撤回成功";
$MiniProgramExamineModel = new MiniProgramExamineModel();
$map = array(
'merchant_id' => $this->merchant_id,
'state' => 1,
);
$history = $MiniProgramExamineModel->getFind($map, '*', 'id desc');
if ($history['status'] != 3) {
$save = array(
'status' => 3,
'revoke_time' => time(),
'reject_operator_id' => session('jurisdiction_user')['id'],
);
$MiniProgramExamineModel->updateOrder(array('id' => $history['id']), $save);
}
} else {
if ($response['errcode'] == 87013) {
$str = "撤回次数达到上限(每天一次,每个月 10 次),错误码:" . $response['errcode'];
} else {
$str = "未知错误" . $response['errcode'];
}
$res['status'] = 0;
$res['msg'] = "审核撤回失败,错误原因:" . $str;
}
return $res;
}
/**
* 发布小程序版本
*/
public function release()
{
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = "https://api.weixin.qq.com/wxa/release?access_token=" . $access_token;
$response = curl_get($url, "{}");
$result = json_decode($response, true);
if ($result['errmsg'] == "ok") {
$MiniProgramExamineModel = new MiniProgramExamineModel();
$map = array(
'merchant_id' => $this->merchant_id,
'status' => 0,
'state' => 1,
);
$history = $MiniProgramExamineModel->getFind($map, '*', 'id desc');
$save = array(
'status' => 4,
'release_time' => time(),
);
$MiniProgramExamineModel->updateOrder(array('id' => $history['id']), $save);
return array('msg' => "发布成功", 'status' => 1);
} else if ($result['errcode'] == "85020") {
return array('msg' => "小程序状态错误,请重新审核提交", 'status' => 0);
} else if ($result['errcode'] == "85052") {
return array('msg' => "小程序已经发布过了", 'status' => 0);
} else {
return array('msg' => "发布失败,错误原因" . $response, 'status' => 0);
}
}
/**
* 小程序版本回退 只能回退一个版本
* @return array
*/
public function reBack()
{
$access_token = get_authorizer_access_tokens($this->merchant_id);
$url = "https://api.weixin.qq.com/wxa/revertcoderelease?access_token=" . $access_token;
$response = curl_getm($url);
$result = json_decode($response, true);
if ($result['errmsg'] == "ok") {
$MiniProgramExamineModel = new MiniProgramExamineModel();
$map = array(
'merchant_id' => $this->merchant_id,
'status' => 4,
'state' => 1,
);
$history = $MiniProgramExamineModel->getFind($map, '*', 'id desc');
$save = array(
'status' => 0,
'state' => 0,
);
$MiniProgramExamineModel->updateOrder(array('id' => $history['id']), $save);
$map = array(
'merchant_id' => $this->merchant_id,
'status' => 4,
'id' => array('lt', $history['id'])
);
$old = $MiniProgramExamineModel->getFind($map, 'id', 'id desc');
$save = array(
'status' => 4,
'state' => 1,
);
$MiniProgramExamineModel->updateOrder(array('id' => $old['id']), $save);
return array('msg' => "回退成功", 'status' => 1);
} else if ($result['errcode'] == "87011") {
return array('msg' => "现网已经在灰度发布,不能进行版本回退", 'status' => 0);
} else if ($result['errcode'] == "87012") {
return array('msg' => "该版本不能回退,可能的原因:1:无上一个线上版用于回退 2:此版本为已回退版本,不能回退 3:此版本为回退功能上线之前的版本,不能回退", 'status' => 0);
} else {
return array('msg' => "回退失败,错误原因" . $response, 'status' => 0);
}
}
/**
* 清除小程序授权记录
* @return mixed
*/
public function clearAuthInfo(){
$AppInfoModel = new AppInfoModel();
$res = $AppInfoModel->deleteOrder(['merchant_id' => $this->merchant_id]);
if ($res) {
return callBack(statusCode()['success'], '清除成功');
} else {
return callBack(statusCode()['error'], '清除失败');
}
}
}

查看文件

@@ -0,0 +1,165 @@
<?php
namespace Addons\Api;
//[1.3.11]
class RedisController
{
static $redis;
/**
* [__construct]
* @param [string] $local [地址]
* @param [int] $port [端口]
* @param [string] $pass [密码]
* @param [int] $number [选择的数据库]
*/
public function __construct()
{
self::$redis = new \Redis();
self::$redis->connect(C('REDIS_LOCAL'), C('REDIS_PORT')); // 连接Redis
self::$redis->auth(C('REDIS_PASS')); // 密码验证
self::$redis->select(C('REDIS_NUMBER')); // 选择数据库
}
/**------------------------------ list --------------------------------------*/
/**
* [rPush 添加,从列表的尾部插入一条数据]
* @param [string] $key [键]
* @param [array] $value [值]
* @param [int] $time [时间]
* @return [bool|int]
*/
public function rPush($key, $value, $time = 0)
{
// 添加队列
$result = self::$redis->rpush($key, $value);
// 判断是否需要设置周期
if ($time && intval($time) > 0){
// 更新周期
self::$redis->expire($key, $time);
}
// 更新周期
return $result;
}
/**
* [lPop 获取,从列表的头部移除,获取一条数据]
* @param [string] $key [键]
* @return [bool|object]
*/
public function lPop($key)
{
$result = self::$redis->lpop($key);
return $result;
}
/**
* [total 获取列表数据]
* @param [string] $key [键]
* @param [string] $start_range [开始位置]
* @param [string] $end_range [结束位置]
* @return [bool|array]
*/
public function getData($key, $start_range = 0, $end_range = -1)
{
$result = self::$redis->lRange($key, $start_range, $end_range);
return $result;
}
/**
* [getLength 获取指定队列长度]
* @param [string] $key [键]
* @return [bool|int]
*/
public function getLength($key)
{
$result = self::$redis->lsize($key);
return $result;
}
/**
* [getStockNumber 下单未支付的订单 获取未支付的库存数量]
* @param [string] $key [键]
* @param [string] $str [元素]
* @return [bool|int]
*/
public function getStockNumber($key, $str)
{
$keys = self::$redis->keys($key);
$count = 0;
foreach ($keys as &$val) {
$data = self::$redis->lRange($val, 0, -1);
$count += intval(json_decode($data[0], true)[$str]);
unset($data);
}
return $count;
}
/**
* [forRPush 循环添加,从列表的尾部插入一条数据]
* @param [string] $key [键]
* @param [array] $value [值]
* @param [int] $time [时间]
* @return [bool|int]
*/
public function forRPush($key, $value, $time = 0)
{
// 定义长度
for ($i = 0; $i < $value; $i++) {
// 添加队列
$result = self::$redis->rpush($key, 1);
if (!$result) {
self::$redis->removeKey($key);
return false;
}
}
// 判断是否需要设置周期
if ($time && intval($time) > 0) {
// 更新周期
self::$redis->expire($key, $time);
}
// 更新周期
return $result;
}
/**
* [forLPop 循环移除,从列表的头部移除一条数据]
* @param [string] $key [键]
* @param [array] $value [值]
* @return [bool|int]
*/
public function forLPop($key, $value)
{
// 定义长度
for ($i = 0; $i < $value; $i++) {
// 添加队列
$result = self::$redis->lpop($key);
if(!$result){
return false;
}
}
return true;
}
/**------------------------------ 公共 --------------------------------------*/
/**
* [existsKey 判断key是否存在]
* @param [string] $key [键]
* @return [bool|int] 存在返回1,不存在返回0
*/
public function existsKey($key)
{
$result = self::$redis->exists($key);
return $result;
}
/**
* [removeKey 移除指定key]
* @param [string] $key [键]
* @return [bool]
*/
public function removeKey($key)
{
$result = self::$redis->delete($key);
return $result;
}
}

查看文件

@@ -0,0 +1,119 @@
<?php
namespace Addons\Api;
//[1.4.13]
class ResultCodeManager
{
//请求结果
const SUCCESS = 0;
const E_FORBIDDEN = 10001;
//缺少参数
const MISS_SIGNATURE = 40001;
const MISS_TOKEN = 40002;
const MISS_REQUIRED_POST = 40003;
const MISS_REQUIRED_GET = 40004;
const MISS_REQUIRED_PARAM = 40005;
const REQUIRED_PARAM_IS_EMPTY = 40006;
//错误参数
const ERROR_TOKEN = 41001;
const ERROR_CAPTCHA_CODE = 41002;
const PARAM_VAL_NOT_EMPTY = 41003;
//无效的参数
const INVALID_TOKEN = 42001;
const INVALID_SIGNATURE = 42002;
const INVALID_CAPTCHA_CODE = 42003;
const PARAMS_NOT_SET = 42004;
//其他错误
const E_SAVE_ERROR = 43001;
const E_SMS_SEND_ERROR = 43002;
const E_REQUEST_EXPIRED = 43003;
const FAIL_TO_SAVE_FILE = 43004;
const INVALID_IMAGE_CONTENT = 43005;
const E_LOGIN_EXPIRED = 43006;
const PARAMS_CLASS_ERROR = 43007;
const DELIVERY_TYPE_ERROR = 43008;
const NO_WIN_PRIZE_RECORD = 43009;
const RECEIVE_TIMEOUT = 43010;
//无数据
const NO_DATA = 44001;
const THE_DATA_NO_HAVE = 44002;
//用户API相关
const NO_USER_DATA = 45001;
const UPLOAD_IMG_ERROR = 45002;
const NO_UPLOAD_DATA = 45003;
//大转盘后台
const HAVE_WIN_RECORD = 46001;
const HAVE_RED_ACTION = 46002;
//配送模板后台
const TEM_TITLE_REPEAT = 47001;
//手机端大转盘相关
const TODAY_TO_MAX = 48001;
const TURNTABLE_TO_MAX = 48002;
const ALL_PRIZE_IS_NULL = 48003;
const PRIZE_IS_NULL = 48004;
const TURNTABLE_CLOSE = 48005;
const WIN_NUM_NULL = 48006;
//硬件商城相关
const CATEGORY_REPEAT = 49001;
static public $messages = array(
self::SUCCESS => "Success",
self::E_FORBIDDEN => "访问被禁止",
self::ERROR_TOKEN => "错误的Token",
self::MISS_SIGNATURE => "缺少必要的参数'signature'",
self::MISS_TOKEN => "缺少必要的参数'token'",
self::INVALID_TOKEN => "无效的Token",
self::MISS_REQUIRED_POST => "缺少必要的POST参数",
self::MISS_REQUIRED_GET => "缺少必要的GET参数",
self::MISS_REQUIRED_PARAM => "缺少必要的参数 '%PARAM%'",
self::E_SAVE_ERROR => "数据保存错误",
self::E_SMS_SEND_ERROR => "短信发送失败",
self::INVALID_SIGNATURE => "无效的Signature",
self::E_REQUEST_EXPIRED => "请求已过期",
self::NO_DATA => "无数据",
self::INVALID_CAPTCHA_CODE => "无效的验证码",
self::ERROR_CAPTCHA_CODE => "错误的验证码",
self::NO_USER_DATA => "没有该用户数据",
self::UPLOAD_IMG_ERROR => "文件上传(移动)失败",
self::NO_UPLOAD_DATA => "没有上传的文件",
self::FAIL_TO_SAVE_FILE => '文件保存失败',
self::INVALID_IMAGE_CONTENT => '无效的图片内容',
self::E_LOGIN_EXPIRED => '登陆过期',
self::THE_DATA_NO_HAVE => '数据不存在',
self::REQUIRED_PARAM_IS_EMPTY => "'%PARAM%' 不能为空",
self::PARAMS_NOT_SET => "参数值不能为空",
self::PARAMS_CLASS_ERROR => "参数类型错误!",
self::PARAM_VAL_NOT_EMPTY => "参数不能为空!",
self::HAVE_WIN_RECORD => "改转盘活动已存在中奖记录不可编辑!",
self::DELIVERY_TYPE_ERROR => "奖品不支持该配送方式!",
self::NO_WIN_PRIZE_RECORD => "中奖记录不存在或已领取!",
self::RECEIVE_TIMEOUT => "不在奖品的领取时间!",
self::TEM_TITLE_REPEAT => "模板名称重复,请重新填写!",
self::HAVE_RED_ACTION => "存在同类型转盘活动或红包活动,不可开启转盘",
self::TODAY_TO_MAX => "今日抽奖上限,请明日再来",
self::TURNTABLE_TO_MAX => "本次活动您已达上限",
self::ALL_PRIZE_IS_NULL => "手速慢了,所有奖品已经被领完了",
self::PRIZE_IS_NULL => "就差0.01秒,大奖被人捷足先登了",
self::TURNTABLE_CLOSE => "很遗憾,活动已经关闭啦",
self::WIN_NUM_NULL => "抽奖机会用完啦~",
self::CATEGORY_REPEAT => "分类名称不能重复",
);
}

查看文件

@@ -0,0 +1,162 @@
<?php
namespace Addons\Api;
/**
* 易连云打印机接口
* @author Alexis
*
*/
class YLYPrinterApi {
/**
* 生成签名sign
*
* @param array $params
* 参数
* @param string $apiKey
* API密钥
* @param string $msign
* 打印机密钥
* @return string sign
*/
public function generateSign($params, $apiKey, $msign) {
// 所有请求参数按照字母先后顺序排
ksort ( $params );
// 定义字符串开始所包括的字符串
$stringToBeSigned = $apiKey;
// 把所有参数名和参数值串在一起
foreach ( $params as $k => $v ) {
$stringToBeSigned .= urldecode ( $k . $v );
}
unset ( $k, $v );
// 定义字符串结尾所包括的字符串
$stringToBeSigned .= $msign;
// 使用MD5进行加密,再转化成大写
return strtoupper ( md5 ( $stringToBeSigned ) );
}
/**
* 生成字符串参数
*
* @param array $param
* 参数
* @return string 参数字符串
*/
public function getStr($param) {
$str = '';
foreach ( $param as $key => $value ) {
$str = $str . $key . '=' . $value . '&';
}
$str = rtrim ( $str, '&' );
return $str;
}
/**
* 打印接口
*
* @param int $partner
* 用户ID
* @param string $machine_code
* 打印机终端号
* @param string $content
* 打印内容
* @param string $apiKey
* API密钥
* @param string $msign
* 打印机密钥
*/
public function action_print($partner, $machine_code, $content, $apiKey, $msign) {
$param = array (
"partner" => $partner,
'machine_code' => $machine_code,
'time' => time ()
);
// 获取签名
$param ['sign'] = $this->generateSign ( $param, $apiKey, $msign );
$param ['content'] = $content;
$str = $this->getStr ( $param );
return $this->sendCmd ( 'http://open.10ss.net:8888', $str );
}
/**
* 添加打印机
*
* @param int $partner
* 用户ID1
* @param string $machine_code
* 打印机终端号
* @param string $username
* 用户名
* @param string $printname
* 打印机名称
* @param string $mobilephone
* 打印机卡号
* @param string $apiKey
* API密钥
* @param string $msign
* 打印机密钥
*/
public function action_addprint($partner, $machine_code, $username, $printname, $mobilephone, $apiKey, $msign) {
$param = array (
'partner' => $partner,
'machine_code' => $machine_code,
'username' => $username,
'printname' => $printname,
'mobilephone' => $mobilephone
);
$param ['sign'] = $this->generateSign ( $param, $apiKey, $msign );
$param ['msign'] = $msign;
$str = $this->getStr ( $param );
echo $this->sendCmd ( 'http://open.10ss.net:8888/addprint.php', $str );
}
/**
* 删除打印机
*
* @param int $partner
* 用户ID
* @param string $machine_code
* 打印机终端号
* @param string $apiKey
* API密钥
* @param string $msign
* 打印机密钥
*/
public function action_removeprinter($partner, $machine_code, $apiKey, $msign) {
$param = array (
'partner' => $partner,
'machine_code' => $machine_code
);
$param ['sign'] = $this->generateSign ( $param, $apiKey, $msign );
$str = $this->getStr ( $param );
echo $this->sendCmd ( 'http://open.10ss.net:8888/removeprint.php', $str );
}
/**
* 发起请求
*
* @param string $url
* 请求地址
* @param string $data
* 请求数据包
* @return string 请求返回数据
*/
public function sendCmd($url, $data) {
$curl = curl_init (); // 启动一个CURL会话
curl_setopt ( $curl, CURLOPT_URL, $url ); // 要访问的地址
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, 0 ); // 对认证证书来源的检测
curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, 2 ); // 从证书中检查SSL加密算法是否存在
curl_setopt ( $curl, CURLOPT_HTTPHEADER, array (
'Expect:'
) ); // 解决数据包大不能提交
curl_setopt ( $curl, CURLOPT_FOLLOWLOCATION, 1 ); // 使用自动跳转
curl_setopt ( $curl, CURLOPT_AUTOREFERER, 1 ); // 自动设置Referer
curl_setopt ( $curl, CURLOPT_POST, 1 ); // 发送一个常规的Post请求
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data ); // Post提交的数据包
curl_setopt ( $curl, CURLOPT_TIMEOUT, 30 ); // 设置超时限制防止死循
curl_setopt ( $curl, CURLOPT_HEADER, 0 ); // 显示返回的Header区域内容
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 ); // 获取的信息以文件流的形式返回
$tmpInfo = curl_exec ( $curl ); // 执行操作
if (curl_errno ( $curl )) {
echo 'Errno' . curl_error ( $curl );
}
curl_close ( $curl ); // 关键CURL会话
return $tmpInfo; // 返回数据
}
}
?>