准备工作:
- 发起方商户编号 parentMerchantNo
- 收款商户编号 merchantNo
- 应用标识 yappid
- 商户私钥 apiPrivateKey
参考文档:
- 支付文档,不建议参考。https://open.yeepay.com/docs/apis/INDUSTRY_SOLUTION/GENERAL/ptssfk/juhezhifu/options__rest__v1.0__aggpay__pre-pay
- 生成私钥文档,较为详细。https://open.yeepay.com/docs/open/platform-doc/developTools-sm/keyTools-sm
SDK下载:
SDK需要放到vendor目录,目录结构vendor/yoppay/xxxx
与官网提供的sdk不一样
添加微信配置(小程序为例)
public function addWxConfig()
{
vendor('yoppay.YopRequest');
$tradeAuthListArray = '["写自己的一级域名,结尾是/"]';//信任谁就加谁
$appidListArray[] = [
'appId' => '你的appId',
'appSecret' => '你的appSecret',
'appIdType' => 'MINI_PROGRAM',//OFFICIAL_ACCOUNT:公众号,MINI_PROGRAM:小程序
'subscribeAppId' => '你的appId'//subscribeAppId 推荐关注appId,必传.可以写自己的
];//二维数组
$appidList = json_encode($appidListArray);
$request = new \YopRequest($this->yappid, $this->apiPrivateKey);
$request->addParam("parentMerchantNo", $this->parentMerchantNo); //发起方商户编号
$request->addParam("merchantNo", $this->merchantNo); //收款商户编号
$request->addParam("tradeAuthDirList", $tradeAuthListArray);
$request->addParam("appIdList", $appidList);
vendor('yoppay.YopRsaClient');
return \YopRsaClient::post("/rest/v2.0/aggpay/wechat-config/add", $request);
}
支付订单(聚合支付统一下单)
public function payOrder($data)
{
vendor('yoppay.YopRequest');
$request = new \YopRequest($this->yappid, $this->apiPrivateKey);
$request->addParam("parentMerchantNo", $this->parentMerchantNo);//发起方商户编号
$request->addParam("merchantNo", $this->merchantNo);//收款商户编号
$request->addParam("orderId", $data['order_num']);//订单号
$request->addParam("orderAmount", 0.01);//订单金额,单位是元,最小值0.01,只能是两位小数
$request->addParam("goodsName", "出行");//商品信息
$request->addParam("notifyUrl", '回调地址u');//回调通知地址
$request->addParam("payWay", 'MINI_PROGRAM');//支付方式 MINI_PROGRAM==小程序
$request->addParam("channel", 'WECHAT');//渠道类型 WECHAT / ALIPAY
$request->addParam("appId", $this->appid);//appid
$request->addParam("userId", 'openid');//openid,appid下对应的openid
$request->addParam("userIp", '127.0.0.1');//ip 需填写真实的ip地址,代码在哪放着就写哪的ip
$request->addParam("scene", 'OFFLINE');//必传,必传offline
vendor('yoppay.YopRsaClient');
$response = \YopRsaClient::post("/rest/v1.0/aggpay/pre-pay", $request);
$data = $this->object_array($response);
return json_decode($data['result']['prePayTn']);
}
回调
public function notifyx()
{
include_once VENDOR_PATH . '/yoppay/Util/YopSignUtils.php';
$source = $_REQUEST['response'];
// 解密
$result = \YopSignUtils::decrypt($source, $this->apiPrivateKey, $this->yeeversePublicKey);
$result = json_decode($result, 'true');
//result包含数据,数据是去敏之后的数据
$result = array (
'channelOrderId' => 'xxasdasd3666868',
'orderId' => 'xxxxx0274',
'bankOrderId' => 'xxxxx20',
'paySuccessDate' => '2023-10-20 17:22:10',
'channel' => 'WECHAT',
'payWay' => 'MINI_PROGRAM',
'uniqueOrderNo' => '1xxxxxx8314878066',
'merchantName' => 'xzxxx服务有限公司',
'orderAmount' => '0.01',
'payAmount' => '0.01',
'payerInfo' => '{"bankCardNo":"","bankId":"CFT","cardType":"DEBIT","mobilePhoneNo":"","userID":"asdasdnuldadsdt8o"}',
'realPayAmount' => '0.01',
'parentMerchantNo' => '65465463',
'tradeType' => 'REALTIME',
'merchantNo' => '56454618463',
'status' => 'SUCCESS',
);
if ($result['status'] == 'SUCCESS') {
//业务逻辑
return 'SUCCESS';
}
return 'FAILED';
}
退款
public function yeeRefund()
{
vendor('yoppay.YopRequest');
$request = new \YopRequest($this->yappid, $this->apiPrivateKey);
$refundOrderNum = '123346453';//退款订单号
$request->addParam("parentMerchantNo", $this->parentMerchantNo);//商户号
$request->addParam("merchantNo", $this->merchantNo);//商户号
$request->addParam("orderId", '123456');//原来的支付订单号,自己生成的
$request->addParam("refundRequestId", $refundOrderNum);//自己生成的退款请求订单号
$request->addParam("refundAmount", 0.01);//退款金额
vendor('yoppay.YopRsaClient');
$response = \YopRsaClient::post("/rest/v1.0/trade/refund", $request);
return $this->object_array($response);
}
公共部分
private $parentMerchantNo = '103421363';
private $merchantNo = '123453123';
private $appid = 'sdfgsdgb4';
private $yappid = 'app_1023523563';
private $apiPrivateKey = 'AA++M6Um5uivOVcAqqJpLwWuoStJKaTElMJ8qS/LRzadoiyZ+BiPDFHMueKCzPgsH6Rqw+JwL2u6e0RCMhbNu62uDmMSpsJGY2yMrZuC2F1AZI9pA+r6Ku/d+Iet09/D4qSSM=';
private $yeeversePublicKey = 'MIIBIjANBgkqhkiG9'
public function getUrl($response, $private_key)
{
$content = $this->toString($response);
include_once VENDOR_PATH . '/yoppay/Util/YopSignUtils.php';
$sign = \YopSignUtils::signRsa($content, $private_key);
$url = $content . "&sign=" . $sign;
return $url;
}
public function toString($arraydata)
{
$Str = "";
foreach ($arraydata as $k => $v) {
$Str .= strlen($Str) == 0 ? "" : "&";
$Str .= $k . "=" . $v;
}
return $Str;
}
public function object_array($array)
{
if (is_object($array)) {
$array = (array)$array;
}
if (is_array($array)) {
foreach ($array as $key => $value) {
$array[$key] = Yee::object_array($value);
}
}
return $array;
}

文章有(2)条网友点评
欣哥 i love you
@ W 卧槽 我这个居然没推送评论数据