230 行
6.4 KiB
PHP
可执行文件
230 行
6.4 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Pay\Library\Cloud;
|
|
|
|
use Pay\Library\Cloud\Cloud as CloudObj;
|
|
|
|
//[1.7.14]
|
|
|
|
/** 云闪付支付
|
|
* Class StarWxPay
|
|
* @package app\common\library\wechat
|
|
*/
|
|
class CloudWxPay
|
|
{
|
|
/**
|
|
* 构造方法
|
|
* WxPay constructor.
|
|
* @param $config
|
|
*/
|
|
static private $errmsg = "CloudWxPay";
|
|
static private $merinfo = [];
|
|
static private $OrgNo;
|
|
static private $Key;
|
|
static private $gatewayUrl = "http://gateway.starpos.com.cn/adpweb/ehpspos3";
|
|
|
|
/** 构造函数,获取该商户所有的相关配置信息
|
|
* StarWxPay constructor.
|
|
* @param $config
|
|
* @throws \think\Exception
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function __construct($config)
|
|
{
|
|
$merinfo['merid'] = $config['cloud_mer_id'];
|
|
$merinfo['cloud_xcx_appid'] = $config['cloud_xcx_appid']; // 商家小程序AppID
|
|
$merinfo['cloud_sub_appid'] = $config['cloud_sub_appid']; // 商家公众号AppID
|
|
$merinfo['serprovid'] = $config['serprovid'];
|
|
$merinfo['acqcode'] = $config['acqcode'];
|
|
$merinfo['prodkey'] = $config['prodkey'];
|
|
$merinfo['prvkey'] = $config['prvkey'];
|
|
$merinfo['pubkey'] = $config['pubkey'];
|
|
$merinfo['backUrl'] = isset($config['backUrl']) ? $config['backUrl'] : '';
|
|
self::$merinfo = $merinfo;
|
|
}
|
|
|
|
public function setBackUrl($backUrl)
|
|
{
|
|
self::$merinfo['backUrl'] = $backUrl;
|
|
return $this;
|
|
}
|
|
|
|
/** 生成支付二维码
|
|
* @param $order_no
|
|
* @param $code
|
|
* @param $total_fee
|
|
* @param $body
|
|
* @return bool
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function native($order_no, $total_fee, $body = '购买商品')
|
|
{
|
|
$merinfo = self::$merinfo;
|
|
$obj = new CloudObj($merinfo);
|
|
$data["orderNo"] = $order_no;
|
|
$data["pay_price"] = $total_fee;
|
|
$data["orderType"] = "wechat";
|
|
$data["body"] = $body;
|
|
$cache = $obj->barCodeAll($data);
|
|
if ($cache) {
|
|
return $cache;
|
|
} else {
|
|
self::$errmsg = $obj->getMsg();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**统一刷卡接口
|
|
* @param $order_no
|
|
* @param $code
|
|
* @param $total_fee
|
|
* @param $body
|
|
* @return bool
|
|
*/
|
|
public function slotCard($order_no, $code, $total_fee, $body)
|
|
{
|
|
$merinfo = self::$merinfo;
|
|
$obj = new CloudObj($merinfo);
|
|
$cache = $obj->slotCard($order_no, $code, $total_fee, $body, "wechat");
|
|
if ($cache) {
|
|
return true;
|
|
} else {
|
|
self::$errmsg = $obj->getMsg();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**统一刷卡接口 2020-10-17
|
|
* @param $order_no
|
|
* @param $code
|
|
* @param $total_fee
|
|
* @param $body
|
|
* @return bool
|
|
*/
|
|
public function slotCard_v1($order_no, $code, $total_fee, $body)
|
|
{
|
|
$merinfo = self::$merinfo;
|
|
$obj = new CloudObj($merinfo);
|
|
$cache = $obj->slotCard_v1($order_no, $code, $total_fee, $body, "wechat");
|
|
if ($cache) {
|
|
return true;
|
|
} else {
|
|
self::$errmsg = $obj->getMsg();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/** 查询订单信息
|
|
* @param $out_trade_no
|
|
* @return bool|mixed|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function queryOrder($out_trade_no)
|
|
{
|
|
$merinfo = self::$merinfo;
|
|
$obj = new CloudObj($merinfo);
|
|
$re = $obj->queryOrder($out_trade_no, 'wechat');
|
|
if ($re) {
|
|
return $re;
|
|
} else {
|
|
self::$errmsg = $obj->getMsg();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/** 微信退款事件
|
|
* @param $order_no
|
|
* @param string $refund_id
|
|
* @param $total_fee
|
|
* @param $refund_fee
|
|
* @param $type 1, 普通微信 2,小程序微信
|
|
* @return mixed|string $total_fee*100
|
|
*/
|
|
public function refund($order_no, $total_fee, $refund_fee, $refund_id = '')
|
|
{
|
|
$merinfo = self::$merinfo;
|
|
$obj = new CloudObj($merinfo);
|
|
$cache = $obj->Refund($order_no, $total_fee, 'wechat', $refund_fee, $refund_id);
|
|
if ($cache) {
|
|
return true;
|
|
} else {
|
|
self::$errmsg = $obj->getMsg();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/** 查询微信退款订单信息
|
|
* @param $out_trade_no
|
|
* @return bool|mixed|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function refundQuery($out_trade_no)
|
|
{
|
|
$merinfo = self::$merinfo;
|
|
$obj = new CloudObj($merinfo);
|
|
$re = $obj->refundQuery($out_trade_no);
|
|
if ($re) {
|
|
return $re;
|
|
} else {
|
|
self::$errmsg = $obj->getMsg();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/** 统一下单功能
|
|
* @param $data
|
|
* @return bool
|
|
*/
|
|
public function unifiedorder($order_no, $open_id, $payPrice, $orderType = 'wechatJs', $body = '')
|
|
{
|
|
$merinfo = self::$merinfo;
|
|
$data["pay_price"] = $payPrice;
|
|
$data["order_no"] = $order_no;
|
|
$data["open_id"] = $open_id;
|
|
$data['orderType'] = $orderType;
|
|
$data['body'] = $body;
|
|
$data['appid'] = $this->upwxconfig($orderType);
|
|
if (!$data['appid']) {
|
|
return false;
|
|
}
|
|
$obj = new CloudObj($merinfo);
|
|
$cache = $obj->unifiedorder($data);
|
|
if ($cache) {
|
|
return $cache;
|
|
} else {
|
|
self::$errmsg = $obj->getMsg();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 查找渠道的appid或者商户自己的appid参数
|
|
*/
|
|
public function upwxconfig($orderType)
|
|
{
|
|
if ($orderType == 'wechatJs') {
|
|
return self::$merinfo['cloud_sub_appid'];
|
|
} else if ($orderType == 'wechatMiniProgram') {
|
|
return self::$merinfo['cloud_xcx_appid'];
|
|
}
|
|
self::$errmsg = '商家appId未正确设置';
|
|
return false;
|
|
}
|
|
|
|
/** 返回错误报告数据
|
|
* @return string
|
|
*/
|
|
public function getMsg()
|
|
{
|
|
return self::$errmsg;
|
|
}
|
|
} |