增加微信付款码支付及静态实例调用

一、增加刷卡支付接口 #30
二、增加静态实例调用
This commit is contained in:
Anyon 2019-11-05 10:21:02 +08:00
parent 5fdc20c4a4
commit 63c2ef5e68
30 changed files with 178 additions and 64 deletions

View File

@ -43,6 +43,12 @@ abstract class BasicAliPay
*/
protected $params;
/**
* 静态缓存
* @var static
*/
private static $cache;
/**
* 正常请求网关
* @var string
@ -88,6 +94,18 @@ abstract class BasicAliPay
}
}
/**
* 静态创建对象
* @param array $config
* @return static
*/
public static function instance(array $config)
{
$key = md5(get_called_class() . serialize($config));
if (isset(self::$cache[$key])) return self::$cache[$key];
return self::$cache[$key] = new static($config);
}
/**
* 查询支付宝订单状态
* @param string $out_trade_no

View File

@ -48,6 +48,12 @@ class BasicWeChat
*/
protected $isTry = false;
/**
* 静态缓存
* @var static
*/
private static $cache;
/**
* 注册代替函数
* @var string
@ -75,6 +81,18 @@ class BasicWeChat
$this->config = new DataArray($options);
}
/**
* 静态创建对象
* @param array $config
* @return static
*/
public static function instance(array $config)
{
$key = md5(get_called_class() . serialize($config));
if (isset(self::$cache[$key])) return self::$cache[$key];
return self::$cache[$key] = new static($config);
}
/**
* 获取访问accessToken
* @return string

View File

@ -36,6 +36,11 @@ class BasicWePay
*/
protected $params;
/**
* 静态缓存
* @var static
*/
private static $cache;
/**
* WeChat constructor.
@ -71,6 +76,18 @@ class BasicWePay
}
}
/**
* 静态创建对象
* @param array $config
* @return static
*/
public static function instance(array $config)
{
$key = md5(get_called_class() . serialize($config));
if (isset(self::$cache[$key])) return self::$cache[$key];
return self::$cache[$key] = new static($config);
}
/**
* 获取微信支付通知
* @return array

View File

@ -18,7 +18,6 @@ use WeChat\Contracts\BasicWePay;
use WeChat\Exceptions\InvalidResponseException;
use WePay\Bill;
use WePay\Order;
use WePay\Refund;
use WePay\Transfers;
use WePay\TransfersBank;
@ -39,10 +38,20 @@ class Pay extends BasicWePay
*/
public function createOrder(array $options)
{
$pay = new Order($this->config->get());
return $pay->create($options);
return Order::instance($this->config->get())->create($options);
}
/**
* 刷卡支付
* @param array $options
* @return array
* @throws Exceptions\LocalCacheException
* @throws InvalidResponseException
*/
public function createMicropay($options)
{
return Order::instance($this->config->get())->micropay($options);
}
/**
* 创建JsApi及H5支付参数
@ -51,8 +60,7 @@ class Pay extends BasicWePay
*/
public function createParamsForJsApi($prepay_id)
{
$pay = new Order($this->config->get());
return $pay->jsapiParams($prepay_id);
return Order::instance($this->config->get())->jsapiParams($prepay_id);
}
/**
@ -62,8 +70,7 @@ class Pay extends BasicWePay
*/
public function createParamsForApp($prepay_id)
{
$pay = new Order($this->config->get());
return $pay->appParams($prepay_id);
return Order::instance($this->config->get())->appParams($prepay_id);
}
/**
@ -73,8 +80,7 @@ class Pay extends BasicWePay
*/
public function createParamsForRuleQrc($product_id)
{
$pay = new Order($this->config->get());
return $pay->qrcParams($product_id);
return Order::instance($this->config->get())->qrcParams($product_id);
}
/**
@ -86,8 +92,7 @@ class Pay extends BasicWePay
*/
public function queryOrder(array $options)
{
$pay = new Order($this->config->get());
return $pay->query($options);
return Order::instance($this->config->get())->query($options);
}
/**
@ -99,8 +104,7 @@ class Pay extends BasicWePay
*/
public function closeOrder($out_trade_no)
{
$pay = new Order($this->config->get());
return $pay->close($out_trade_no);
return Order::instance($this->config->get())->close($out_trade_no);
}
/**
@ -112,8 +116,7 @@ class Pay extends BasicWePay
*/
public function createRefund(array $options)
{
$pay = new Refund($this->config->get());
return $pay->create($options);
return Order::instance($this->config->get())->create($options);
}
/**
@ -125,8 +128,7 @@ class Pay extends BasicWePay
*/
public function queryRefund(array $options)
{
$pay = new Refund($this->config->get());
return $pay->query($options);
return Order::instance($this->config->get())->query($options);
}
/**
@ -138,8 +140,7 @@ class Pay extends BasicWePay
*/
public function report(array $options)
{
$pay = new Order($this->config->get());
return $pay->report($options);
return Order::instance($this->config->get())->report($options);
}
/**
@ -151,8 +152,7 @@ class Pay extends BasicWePay
*/
public function queryAuthCode($authCode)
{
$pay = new Order($this->config->get());
return $pay->queryAuthCode($authCode);
return Order::instance($this->config->get())->queryAuthCode($authCode);
}
/**
@ -165,11 +165,9 @@ class Pay extends BasicWePay
*/
public function billDownload(array $options, $outType = null)
{
$pay = new Bill($this->config->get());
return $pay->download($options, $outType);
return Bill::instance($this->config->get())->download($options, $outType);
}
/**
* 拉取订单评价数据
* @param array $options
@ -179,8 +177,7 @@ class Pay extends BasicWePay
*/
public function billCommtent(array $options)
{
$pay = new Bill($this->config->get());
return $pay->comment($options);
return Bill::instance($this->config->get())->comment($options);
}
/**
@ -192,8 +189,7 @@ class Pay extends BasicWePay
*/
public function createTransfers(array $options)
{
$pay = new Transfers($this->config->get());
return $pay->create($options);
return Transfers::instance($this->config->get())->create($options);
}
/**
@ -205,8 +201,7 @@ class Pay extends BasicWePay
*/
public function queryTransfers($partner_trade_no)
{
$pay = new Transfers($this->config->get());
return $pay->query($partner_trade_no);
return Transfers::instance($this->config->get())->query($partner_trade_no);
}
/**
@ -219,8 +214,7 @@ class Pay extends BasicWePay
*/
public function createTransfersBank(array $options)
{
$pay = new TransfersBank($this->config->get());
return $pay->create($options);
return TransfersBank::instance($this->config->get())->create($options);
}
/**
@ -232,7 +226,6 @@ class Pay extends BasicWePay
*/
public function queryTransFresBank($partner_trade_no)
{
$pay = new TransfersBank($this->config->get());
return $pay->query($partner_trade_no);
return TransfersBank::instance($this->config->get())->query($partner_trade_no);
}
}

View File

@ -38,6 +38,19 @@ class Order extends BasicWePay
return $this->callPostApi($url, $options, false, 'MD5');
}
/**
* 刷卡支付
* @param array $options
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function micropay(array $options)
{
$url = 'https://api.mch.weixin.qq.com/pay/micropay';
return $this->callPostApi($url, $options, false, 'MD5');
}
/**
* 查询订单
* @param array $options

View File

@ -20,8 +20,9 @@ $config = include "./alipay.php";
try {
// 实例支付对象
$pay = \We::AliPayApp($config);
// $pay = \We::AliPayApp($config);
// $pay = new \AliPay\App($config);
$pay = \AliPay\App::instance($config);
// 请参考请求参数https://docs.open.alipay.com/api_1/alipay.trade.app.pay
$result = $pay->apply([

View File

@ -20,8 +20,10 @@ $config = include "./alipay.php";
try {
// 实例支付对象
$pay = \We::AliPayBill($config);
// $pay = new \AliPay\Bill($config);
// $pay = \We::AliPayBill($config);
$pay = \AliPay\Bill::instance($config);
// 请参考请求参数https://docs.open.alipay.com/api_15/alipay.data.dataservice.bill.downloadurl.query
$result = $pay->apply([
'bill_date' => '2018-10-03', // 账单时间(日账单yyyy-MM-dd,月账单 yyyy-MM)

View File

@ -20,8 +20,10 @@ $config = include "./alipay.php";
try {
// 实例支付对象
$pay = \We::AliPayApp($config);
// $pay = \We::AliPayApp($config);
// $pay = new \AliPay\App($config);
$pay = \AliPay\App::instance($config);
$data = $pay->notify();
if (in_array($data['trade_status'], ['TRADE_SUCCESS', 'TRADE_FINISHED'])) {
// @todo 更新订单状态,支付完成

View File

@ -20,8 +20,10 @@ $config = include "./alipay.php";
try {
// 实例支付对象
$pay = We::AliPayPos($config);
// $pay = We::AliPayPos($config);
// $pay = new \AliPay\Pos($config);
$pay = \AliPay\Pos::instance($config);
// 参数链接https://docs.open.alipay.com/api_1/alipay.trade.pay
$result = $pay->apply([
'out_trade_no' => '4312412343', // 订单号
@ -29,6 +31,7 @@ try {
'subject' => '订单商品标题', // 订单商品标题
'auth_code' => '123456', // 授权码
]);
echo '<pre>';
var_export($result);
} catch (Exception $e) {

View File

@ -25,10 +25,13 @@ $refund_fee = '1.00';
try {
// 实例支付对象
$pay = We::AliPayApp($config);
// $pay = We::AliPayApp($config);
// $pay = new \AliPay\App($config);
$pay = \AliPay\App::instance($config);
// 参考链接https://docs.open.alipay.com/api_1/alipay.trade.refund
$result = $pay->refund($out_trade_no, $refund_fee);
echo '<pre>';
var_export($result);
} catch (Exception $e) {

View File

@ -20,14 +20,17 @@ $config = include "./alipay.php";
try {
// 实例支付对象
$pay = We::AliPayScan($config);
// $pay = We::AliPayScan($config);
// $pay = new \AliPay\Scan($config);
$pay = \AliPay\Scan::instance($config);
// 参考链接https://docs.open.alipay.com/api_1/alipay.trade.precreate
$result = $pay->apply([
'out_trade_no' => '14321412', // 订单号
'total_amount' => '13', // 订单金额,单位:元
'subject' => '订单商品标题', // 订单商品标题
]);
echo '<pre>';
var_export($result);
} catch (Exception $e) {

View File

@ -20,8 +20,10 @@ $config = include "./alipay.php";
try {
// 实例支付对象
$pay = We::AliPayTransfer($config);
// $pay = new \AliPay\Scan($config);
// $pay = We::AliPayTransfer($config);
// $pay = new \AliPay\Transfer($config);
$pay = \AliPay\Transfer::instance($config);
// 参考链接https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer
$result = $pay->apply([
'out_biz_no' => time(), // 订单号
@ -32,6 +34,7 @@ try {
'payee_real_name' => '张三', // 收款方真实姓名
'remark' => '张三', // 转账备注
]);
echo '<pre>';
var_export($result);
} catch (Exception $e) {

View File

@ -23,14 +23,17 @@ $config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';
try {
// 实例支付对象
$pay = We::AliPayWap($config);
// $pay = We::AliPayWap($config);
// $pay = new \AliPay\Wap($config);
$pay = \AliPay\Wap::instance($config);
// 参考链接https://docs.open.alipay.com/api_1/alipay.trade.wap.pay
$result = $pay->apply([
'out_trade_no' => time(), // 商户订单号
'total_amount' => '1', // 支付金额
'subject' => '支付订单描述', // 支付订单描述
]);
echo $result;
} catch (Exception $e) {
echo $e->getMessage();

View File

@ -24,14 +24,17 @@ $config['return_url'] = 'http://pay.thinkadmin.top/test/alipay-success.php';
try {
// 实例支付对象
$pay = We::AliPayWeb($config);
// $pay = We::AliPayWeb($config);
// $pay = new \AliPay\Web($config);
$pay = \AliPay\Web::instance($config);
// 参考链接https://docs.open.alipay.com/api_1/alipay.trade.page.pay
$result = $pay->apply([
'out_trade_no' => time(), // 商户订单号
'total_amount' => '1', // 支付金额
'subject' => '支付订单描述', // 支付订单描述
]);
echo $result;
} catch (Exception $e) {
echo $e->getMessage();

View File

@ -13,7 +13,11 @@ $iv = 'ltM/wT7hsAl0TijEBI4v/g==';
$code = '013LyiTR0TwjC92QjJRR0mEsTR0LyiT3';
$decode = 'eIoVtIC2YzLCnrwiIs1IBbXMvC0vyL8bo1IhD38fUQIRbk3lgTWa0Hdw/Ty7NTs3iu7YlqqZBti+cxd6dCfeXBUQwTO2QpbHg0WTeDAdrihsHRHm4dCWdfTx8rzDloGbNOIsKdRElIhUH5YFdiTr5AYiufUDb34cwJ4GNWLAUq4bR0dmFeVEi+3nfwe2MAjGYDl4aq719VLsHodOggK6lXZvM5wjoDyuZsK2dPqJr3/Ji30Z0mdyFq32R4uR3rtJH/h+Rj0+/QmE9QYG7Y6Z48hgPE8cpnhRQNwH49jnC/zKZ9wtDkQ/J8J3Ed2i58zcuY01v8IV+pZ8oBUKXfO5ha+APOxtBSTzyHraU/2RGo8UWtOF6h64OQZhd/UQQy362eyc/qoq8sF9JnEFRP0mRmTDJ+u9oyDhxswCu6x8V73ERWaJeEGSCyjiGpep7/DxZ6eSSBq36OB0BWBkJqsq9Q==';
$sessionKey = 'OetNxl86B/yMpbwG6wtMEw==';
$mini = new WeMini\Crypt($config);
// $mini = \We::WeMiniCrypt($config);
// $mini = new WeMini\Crypt($config);
$mini = \WeMini\Crypt::instance($config);
echo '<pre>';
//print_r($mini->session($code));
print_r($mini->decode($iv, $sessionKey, $decode));

View File

@ -10,13 +10,13 @@ $config = [
//We::config($config);
$mini = We::WeMiniQrcode($config);
//$mini = new WeMini\Qrcode($config);
// $mini = We::WeMiniQrcode($config);
// $mini = new WeMini\Qrcode($config);
$mini = \WeMini\Qrcode::instance($config);
//echo '<pre>';
try {
header('Content-type:image/jpeg');//输出的类型
header('Content-type:image/jpeg'); //输出的类型
// echo $mini->createDefault('pages/index?query=1');
// echo $mini->createMiniScene('432432', 'pages/index/index');
echo $mini->createMiniPath('pages/index?query=1');

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = [

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = '1217752501201407033233368018';

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = [

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 获取通知参数
$data = $wechat->getNotify();

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = [

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WePay\Redpack($config);
// $wechat = new \WePay\Redpack($config);
// $wechat = \We::WePayRedpack($config);
$wechat = \WePay\Redpack::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = [

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = [

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = [

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = [

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Pay($config);
// $wechat = new \WeChat\Pay($config);
// $wechat = \We::WeChatPay($config);
$wechat = \WeChat\Pay::instance($config);
// 4. 组装参数,可以参考官方商户文档
$options = [

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Script($config);
// $wechat = \We::WeChatScript($config);
// $wechat = new \WeChat\Script($config);
$wechat = \WeChat\Script::instance($config);
// 4. 获取JSSDK网址签名配置
$result = $wechat->getJsSign('http://a.com/test.php');

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$menu = new \WeChat\Menu($config);
// $menu = \We::WeChatMenu($config);
// $menu = new \WeChat\Menu($config);
$menu = \WeChat\Menu::instance($config);
// 4. 获取菜单数据
$result = $menu->get();

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\Qrcode($config);
// $wechat = \We::WeChatQrcode($config);
// $wechat = new \WeChat\Qrcode($config);
$wechat = \WeChat\Qrcode::instance($config);
// 4. 获取用户列表
$result = $wechat->create('场景内容');

View File

@ -21,7 +21,9 @@ try {
$config = include "./config.php";
// 3. 创建接口实例
$wechat = new \WeChat\User($config);
// $wechat = \We::WeChatUser($config);
// $wechat = new \WeChat\User($config);
$wechat = \WeChat\User::instance($config);
// 4. 获取用户列表
$result = $wechat->getUserList();