Commit c43e9fb6 by 丁铜欣

test

1 parent 32366972
<?php
namespace Payment\Charge\WNFPay;
use Payment\Common\WnfConfig;
use Payment\Common\WNFpay\Data\Charge\ChargeData;
use Payment\Common\WNFpay\WNFBaseStrategy;
class WNFCharge extends WNFBaseStrategy
{
/**
* 获取支付对应的数据完成类
*
* @return BaseData
*/
public function getBuildDataClass(){
// TODO: Implement getBuildDataClass() method.
return ChargeData::class;
}
protected function getReqUrl($url = null){
return parent::getReqUrl($url??WnfConfig::PAY_URL); // TODO: Change the autogenerated stub
}
}
\ No newline at end of file
...@@ -43,6 +43,7 @@ use Payment\Charge\Wx\WxWapCharge; ...@@ -43,6 +43,7 @@ use Payment\Charge\Wx\WxWapCharge;
use Payment\Charge\YS\YSNatCharge; use Payment\Charge\YS\YSNatCharge;
use Payment\Charge\YS\YSPubCharge; use Payment\Charge\YS\YSPubCharge;
use Payment\Charge\YS\YSScanCharge; use Payment\Charge\YS\YSScanCharge;
use Payment\Charge\WNFPay\WNFCharge;
use Payment\Charge\YSE\YSEPubCharge; use Payment\Charge\YSE\YSEPubCharge;
use Payment\Common\BaseStrategy; use Payment\Common\BaseStrategy;
...@@ -211,8 +212,12 @@ class ChargeContext ...@@ -211,8 +212,12 @@ class ChargeContext
case Config::YSE_CHANNEL_LITE: //小程序、公众号 case Config::YSE_CHANNEL_LITE: //小程序、公众号
$this->channel = new YSEPubCharge($config); $this->channel = new YSEPubCharge($config);
break; break;
case Config::WNF_WECHAT_LITE:
case Config::WNF_ALI_APP:
$this->channel = new WNFCharge($config);
break;
default: default:
throw new PayException('当前支持:支付宝、微信、招商一网通、通联支付、米付支付、扫呗支付、富友支付、联拓富、易生支付。'); throw new PayException('当前支持:支付宝、微信、招商一网通、通联支付、米付支付、扫呗支付、富友支付、联拓富、易生支付、微诺付。');
} }
} catch (PayException $e) { } catch (PayException $e) {
throw $e; throw $e;
......
...@@ -64,6 +64,10 @@ class Charge ...@@ -64,6 +64,10 @@ class Charge
//盛银支付 //盛银支付
Config::YSE_CHANNEL_PUB, Config::YSE_CHANNEL_PUB,
Config::YSE_CHANNEL_LITE, Config::YSE_CHANNEL_LITE,
//微诺付
Config::WNF_WECHAT_LITE,
Config::WNF_ALI_APP
]; ];
/** /**
......
...@@ -49,6 +49,8 @@ class Query ...@@ -49,6 +49,8 @@ class Query
Config::YS_QUERY,//易生 Config::YS_QUERY,//易生
Config::YSE_QUERY,//易生 Config::YSE_QUERY,//易生
Config::WNF_QUERY,//微诺付
]; ];
/** /**
......
...@@ -67,6 +67,8 @@ abstract class BaseData ...@@ -67,6 +67,8 @@ abstract class BaseData
$this->channel = Config::YSE_PAY; $this->channel = Config::YSE_PAY;
}elseif ($config instanceof SwThreeConfig) { }elseif ($config instanceof SwThreeConfig) {
$this->channel = Config::SW_T_PAY; $this->channel = Config::SW_T_PAY;
}elseif ($config instanceof WnfConfig) {
$this->channel = Config::WNF_PAY;
} }
$this->data = array_merge($config->toArray(), $reqData);//配置信息合并 $this->data = array_merge($config->toArray(), $reqData);//配置信息合并
...@@ -131,6 +133,9 @@ abstract class BaseData ...@@ -131,6 +133,9 @@ abstract class BaseData
case Config::TL_PAY: case Config::TL_PAY:
$this->retData['sign'] = ArrayUtil::SignArray($data, $this->md5Key); //签名 $this->retData['sign'] = ArrayUtil::SignArray($data, $this->md5Key); //签名
break; break;
case Config::WNF_PAY:
$this->makeSign('');
break;
case Config::MI_PAY: case Config::MI_PAY:
$basePath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'CacertFile' . DIRECTORY_SEPARATOR; $basePath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'CacertFile' . DIRECTORY_SEPARATOR;
$this->cacertPath = "{$basePath}mipay" . DIRECTORY_SEPARATOR . "ldy_private_key.pem"; $this->cacertPath = "{$basePath}mipay" . DIRECTORY_SEPARATOR . "ldy_private_key.pem";
......
<?php
namespace Payment\Common\WNFpay\Data\Charge;
use Payment\Common\PayException;
use Payment\Common\WNFpay\WNFBaseData;
use Payment\Utils\ArrayUtil;
abstract class ChargeData extends WNFBaseData
{
/**
* 构建用于支付的签名相关数据
*
* @return void
*/
protected function buildData(){
$data = [
'customerOrderNo' => $this->customerOrderNo,
'amount' => $this->amount,
'subject' => $this->subject,
'sellerNote' => $this->sellerNote,
'userid' => $this->userid,//用户标识
'appid' => $this->appid,
'payType' => $this->payType,
'callbackUrl' => $this->callbackUrl,
'goodsListItem ' => $this->goodsListItem//商品列表,此处应该是数组
];
$this->retData = $data;
}
/**
* 参数校验
* @return mixed|void
* @throws PayException
*/
protected function checkDataParam(){
parent::checkDataParam();
if(empty($this->callbackUrl)){
throw new PayException('支付通知地址不能为空');
}
if(empty($this->amount)){
throw new PayException('金额不能为空');
}
if(empty($this->subject)){
throw new PayException('交易商品不能为空');
}
if(empty($this->sellerNote)){
throw new PayException('商户备注不能为空');
}
if(empty($this->userid)){
throw new PayException('用户标识不能为空');
}
if(empty($this->appid)){
throw new PayException('小程序appid不能为空');
}
if(empty($this->payType)){
throw new PayException('支付类型 不能为空');
}
if(empty($this->goodsListItem)){
throw new PayException('商品列表不能为空');
}
}
}
\ No newline at end of file
<?php
namespace Payment\Common\WNFpay;
use Payment\Common\BaseData;
abstract class WNFBaseData extends BaseData
{
protected $key = '797cx89nlsaz98ljakntnm6712561';
protected function makeSign($signStr){
list($microsecond , $time) = explode(' ', microtime()); //' '中间是一个空格
$timestamp = (float)sprintf('%.0f',(floatval($microsecond)+floatval($time))*1000);
$this->retData['sign'] = $sign = md5(md5($this->key . $timestamp) . md5($timestamp));
return $sign;
}
}
\ No newline at end of file
<?php
namespace Payment\Common\WNFpay;
use Payment\Common\BaseData;
use Payment\Common\BaseStrategy;
use Payment\Common\PayException;
use Payment\Common\WnfConfig;
use Payment\Common\YSConfig;
use Payment\Utils\ArrayUtil;
use Payment\Utils\Curl;
abstract class WNFBaseStrategy implements BaseStrategy
{
protected $config;
/**
* 支付数据
* @var BaseData $reqData
*/
protected $reqData;
/**
* FuBaseStrategy constructor.
* @param array $config
* @throws PayException
*/
public function __construct(array $config)
{
/* 设置内部字符编码为 UTF-8 */
mb_internal_encoding("UTF-8");
try {
$this->config = new WnfConfig($config);
} catch (PayException $e) {
throw $e;
}
}
/**
* 发送完了请求
* @param $body
* @return mixed
* @throws \Payment\Common\PayException
*/
protected function sendReq($body)
{
$url = $this->getReqUrl();
if (is_null($url)) {
throw new PayException('目前不支持该接口。请联系开发者添加');
}
$responseTxt = $this->curlPost($body, $url);
if($responseTxt['code'] != 200) {
throw new PayException('支付异常-信息'.$responseTxt['message']);
}
return $responseTxt;
}
protected function curlPost($body, $url)
{
$curl = new Curl();
return $curl->set([
'CURLOPT_HEADER' => 0
])->post($body, $url)->submit($url);
}
/**
* 处理具体的业务
*
* @param array $data
* @return mixed
* @throws \Payment\Common\PayException
*/
public function handle(array $data)
{
// TODO: Implement handle() method.
$buildClass = $this->getBuildDataClass();
try {
$this->reqData = new $buildClass($this->config, $data);
} catch (PayException $e) {
throw $e;
}
$this->reqData->setSign();
$body = $this->reqData->getData();
$ret = $this->sendReq($body);
return $this->retData($ret);
}
/**
* 获取请求地址
* @param null $url
* @return string
*/
protected function getReqUrl()
{
return WnfConfig::PAY_URL;
}
/**
* 处理支付平台的返回值并返回给客户端
* @param array $ret
* @return mixed
*
*/
protected function retData(array $ret)
{
return $ret;
}
}
\ No newline at end of file
<?php
namespace Payment\Common;
use Payment\Utils\ArrayUtil;
class WnfConfig extends ConfigInterface
{
// 下单url
const PAY_URL = 'http://mall.sdinvoice.com/api/pay';
// 查询url
const QUERY_URL = 'http://mall.sdinvoice.com/api/query';
// 指定回调页面
public $returnUrl;
public $key;
/**
* FuConfig constructor.
* @param array $config
* @throws PayException
*/
public function __construct(array $config)
{
try {
$this->initConfig($config);
} catch (PayException $e) {
throw $e;
}
}
/**
* 初始化配置文件参数
* @param array $config
* @throws PayException
*/
private function initConfig(array $config)
{
// $config = ArrayUtil::paraFilter($config);
// if (key_exists('key', $config) && !empty($config['key'])) $this->key = $config['key'];else throw new PayException('支付密钥不存在');
}
}
\ No newline at end of file
...@@ -38,6 +38,8 @@ final class Config{ ...@@ -38,6 +38,8 @@ final class Config{
const SW_T_PAY = 'swpay_t'; //扫呗支付(3.0) const SW_T_PAY = 'swpay_t'; //扫呗支付(3.0)
const WNF_PAY = 'wnfpay'; //微诺付
//========================= 金额问题设置 =======================// //========================= 金额问题设置 =======================//
const PAY_MIN_FEE = '0.01';// 支付的最小金额 const PAY_MIN_FEE = '0.01';// 支付的最小金额
...@@ -261,4 +263,12 @@ final class Config{ ...@@ -261,4 +263,12 @@ final class Config{
const YSE_CHANNEL_LITE = 'yse_lite';// 小程序支付 const YSE_CHANNEL_LITE = 'yse_lite';// 小程序支付
//=============================微诺付==================================
const WNF_WECHAT_LITE = 'wnf_wx_lite'; //微信支付
const WNF_ALI_APP = 'wnf_ali_lite'; //支付宝支付
const WNF_QUERY = 'wnf_query'; //支付查询
} }
...@@ -113,8 +113,10 @@ class QueryContext ...@@ -113,8 +113,10 @@ class QueryContext
case Config::YSE_QUERY://银盛支付 case Config::YSE_QUERY://银盛支付
$this->query = new YSEChargeQuery($config); $this->query = new YSEChargeQuery($config);
break; break;
case Config::WNF_QUERY://微诺付
break;
default: default:
throw new PayException('当前仅支持:ALI_CHARGE ALI_REFUND WX_CHARGE WX_REFUND WX_TRANSFER WX_PAY_BANK CMB_CHARGE CMB_REFUND TLPAY MI_QUERY SW_QUERY FU_CHARGE FU_REFUND'); throw new PayException('当前仅支持:ALI_CHARGE ALI_REFUND WX_CHARGE WX_REFUND WX_TRANSFER WX_PAY_BANK CMB_CHARGE CMB_REFUND TLPAY MI_QUERY SW_QUERY FU_CHARGE FU_REFUND WNF_QUERY');
} }
} catch (PayException $e) { } catch (PayException $e) {
throw $e; throw $e;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!