Commit 4a312217 by Administrator

Merge branch 'dev_dtx' into 'master'

合并微诺付支付通道

See merge request !5
2 parents 32366972 afd6c275
<?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;
use Payment\Charge\YS\YSNatCharge;
use Payment\Charge\YS\YSPubCharge;
use Payment\Charge\YS\YSScanCharge;
use Payment\Charge\WNFPay\WNFCharge;
use Payment\Charge\YSE\YSEPubCharge;
use Payment\Common\BaseStrategy;
......@@ -211,8 +212,12 @@ class ChargeContext
case Config::YSE_CHANNEL_LITE: //小程序、公众号
$this->channel = new YSEPubCharge($config);
break;
case Config::WNF_WECHAT_LITE:
case Config::WNF_ALI_APP:
$this->channel = new WNFCharge($config);
break;
default:
throw new PayException('当前支持:支付宝、微信、招商一网通、通联支付、米付支付、扫呗支付、富友支付、联拓富、易生支付。');
throw new PayException('当前支持:支付宝、微信、招商一网通、通联支付、米付支付、扫呗支付、富友支付、联拓富、易生支付、微诺付。');
}
} catch (PayException $e) {
throw $e;
......
......@@ -64,6 +64,10 @@ class Charge
//盛银支付
Config::YSE_CHANNEL_PUB,
Config::YSE_CHANNEL_LITE,
//微诺付
Config::WNF_WECHAT_LITE,
Config::WNF_ALI_APP
];
/**
......
......@@ -49,6 +49,8 @@ class Query
Config::YS_QUERY,//易生
Config::YSE_QUERY,//易生
Config::WNF_QUERY,//微诺付
];
/**
......
......@@ -67,8 +67,9 @@ abstract class BaseData
$this->channel = Config::YSE_PAY;
}elseif ($config instanceof SwThreeConfig) {
$this->channel = Config::SW_T_PAY;
}elseif ($config instanceof WnfConfig) {
$this->channel = Config::WNF_PAY;
}
$this->data = array_merge($config->toArray(), $reqData);//配置信息合并
try {
$this->checkDataParam();
......@@ -131,6 +132,9 @@ abstract class BaseData
case Config::TL_PAY:
$this->retData['sign'] = ArrayUtil::SignArray($data, $this->md5Key); //签名
break;
case Config::WNF_PAY:
$this->makeSign('');
break;
case Config::MI_PAY:
$basePath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'CacertFile' . DIRECTORY_SEPARATOR;
$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;
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,//商品列表,此处应该是数组
'taxNo' => $this->taxNo ?? '',
'appKey' => $this->appKey ?? '',
'deptId' => $this->deptId ?? ''
];
$this->retData = $data;
}
/**
* 参数校验
* @return mixed|void
* @throws PayException
*/
protected function 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\Data\Query;
use Payment\Common\BaseData;
use Payment\Common\PayException;
use Payment\Common\WNFpay\WNFBaseData;
class ChargeQueryData extends WNFBaseData
{
/**
* 构建用于支付的签名相关数据
*
* @return void
*/
protected function buildData(){
$data = [
'customerOrderNo' => $this->customerOrderNo,
];
$this->retData = $data;
}
/**
* 检查传入的参数. $reqData是否正确.
*
* @return mixed
* @throws PayException
*/
protected function checkDataParam(){
if(empty($this->customerOrderNo)){
throw new PayException('订单号不能为空');
}
}
}
\ No newline at end of file
<?php
namespace Payment\Common\WNFpay;
use Payment\Common\BaseData;
abstract class WNFBaseData extends BaseData
{
protected function makeSign($signStr){
list($microsecond , $time) = explode(' ', microtime()); //' '中间是一个空格
$timestamp = (float)sprintf('%.0f',(floatval($microsecond)+floatval($time))*1000);
$this->retData['timestamp'] = $timestamp;
$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);
return $responseTxt;
}
protected function curlPost($body, $url)
{
$curl = new Curl();
return $curl->set([
'CURLOPT_HEADER' => 0,
'CURLOPT_HTTPHEADER' => ['Content-Type: application/json']
])->post($body, $url)->submit($url,false,true);
}
/**
* 处理具体的业务
*
* @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($url = null)
{
return $url ?? WnfConfig::PAY_URL;
}
/**
* 处理支付平台的返回值并返回给客户端
* @param array $ret
* @return mixed
*
*/
protected function retData(array $ret)
{
return $ret['body'];
}
}
\ 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{
const SW_T_PAY = 'swpay_t'; //扫呗支付(3.0)
const WNF_PAY = 'wnfpay'; //微诺付
//========================= 金额问题设置 =======================//
const PAY_MIN_FEE = '0.01';// 支付的最小金额
......@@ -261,4 +263,12 @@ final class Config{
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'; //支付查询
}
<?php
namespace Payment\Query\WNF;
use Payment\Common\WNFpay\WNFBaseStrategy;
use Payment\Common\WnfConfig;
use Payment\Common\WNFpay\Data\Query\ChargeQueryData;
class WNFChargeQuery extends WNFBaseStrategy
{
public function getBuildDataClass(){
return ChargeQueryData::class;
}
/**
* 返回
* @param null $url
* @return string
*/
public function getReqUrl($url = null){
return parent::getReqUrl($url ?? WnfConfig::QUERY_URL); // TODO: Change the autogenerated stub
}
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ use Payment\Query\Wx\WxRefundQuery;
use Payment\Query\Wx\WxTransferQuery;
use Payment\Query\YS\YSChargeQuery;
use Payment\Query\YSE\YSEChargeQuery;
use Payment\Query\WNF\WNFChargeQuery;
class QueryContext
{
......@@ -113,8 +114,11 @@ class QueryContext
case Config::YSE_QUERY://银盛支付
$this->query = new YSEChargeQuery($config);
break;
case Config::WNF_QUERY://微诺付
$this->query = new WNFChargeQuery($config);
break;
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) {
throw $e;
......
......@@ -17,6 +17,7 @@ class Curl
private $default;
private $download;
private $isJsonStr=false;
private $isWnfJson=false;
private static $instance;
public function __construct()
......@@ -122,7 +123,7 @@ class Curl
* @param string $url
* @return array
*/
public function submit($url,$isJsonStr= false)
public function submit($url,$isJsonStr= false, $isWnfJson = false)
{
if (! $this->post) {
return array(
......@@ -131,6 +132,7 @@ class Curl
);
}
$this->isJsonStr = $isJsonStr;
$this->isWnfJson = $isWnfJson;
return $this->set('CURLOPT_URL', $url)->exec();
}
......@@ -222,6 +224,8 @@ class Curl
curl_setopt($ch, CURLOPT_POST, true);
if($this->isJsonStr){
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($this->postFieldsBuild($this->post)));
}elseif ($this->isWnfJson){//微诺付json字符串不能一维化
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($this->post));
}else{
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postFieldsBuild($this->post));
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!