|
|
@@ -6,133 +6,131 @@ use Yii;
|
|
|
use common\components\util;
|
|
|
use common\services\xhPayToolService;
|
|
|
use bizTy\sj\services\MerchantExtendService;
|
|
|
-use common\services\xhUserAssetService;
|
|
|
-use common\services\xhUserService;
|
|
|
use common\services\xhOrderService;
|
|
|
-use common\components\configDict;
|
|
|
-use common\services\xhMerchantService;
|
|
|
|
|
|
class NoticeController extends PublicController
|
|
|
{
|
|
|
-
|
|
|
- public $categoryList;
|
|
|
-
|
|
|
- //微信支付异步回调
|
|
|
- public function actionWxCallback()
|
|
|
- {
|
|
|
- $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
|
|
|
- if (empty($postStr)) {
|
|
|
- util::end();
|
|
|
- }
|
|
|
- $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
|
|
|
- if ($postObj->return_code != 'SUCCESS') {
|
|
|
- Yii::warning('return_code error:' . $postObj->return_code);
|
|
|
- util::end();
|
|
|
- }
|
|
|
- $orderId = $postObj->out_trade_no;
|
|
|
- $total_fee = $postObj->total_fee;
|
|
|
- $totalFee = $total_fee / 100;
|
|
|
- $attach = $postObj->attach;
|
|
|
- //接收流水类型、代金劵
|
|
|
- parse_str($attach);
|
|
|
- $couponId = isset($couponId) ? $couponId : 0;
|
|
|
- //流水类型
|
|
|
- $capitalType = isset($capitalType) ? $capitalType : null;
|
|
|
- $wxPayType = isset($wxPayType) ? $wxPayType : 0;
|
|
|
- if (isset($capitalType) == false) {
|
|
|
- Yii::warning('capitalType empty,orderId:' . $orderId);
|
|
|
- util::end();
|
|
|
- }
|
|
|
- $callbackParams = ['wxPayType' => $wxPayType];
|
|
|
- $return = xhPayToolService::weixinPay($callbackParams, $orderId, $totalFee, $capitalType, $couponId);//支付回调流程
|
|
|
- if ($return['code'] == 'A0002') {
|
|
|
- Yii::warning('callback exec and failed,capitalType:' . $capitalType . ' orderId:' . $orderId);
|
|
|
- util::end();
|
|
|
- }
|
|
|
- echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
|
|
|
- }
|
|
|
-
|
|
|
- //支付宝异步通知
|
|
|
- public function actionAlipayCallback()
|
|
|
- {
|
|
|
- header("Content-type: text/html; charset=utf-8");
|
|
|
- $alipayWap = Yii::getAlias("@vendor/alipayWap");
|
|
|
- $orderSn = $_POST['out_trade_no'];//商户订单号
|
|
|
- $pay = xhOrderService::getByOrderSn($orderSn);
|
|
|
- if (empty($pay)) {
|
|
|
- Yii::warning('没有找到订单:orderSn:' . $orderSn);
|
|
|
- util::end();
|
|
|
- }
|
|
|
- $orderId = $pay['id'];//商户订单号
|
|
|
- $merchantId = isset($pay['merchantId']) ? $pay['merchantId'] : 0;
|
|
|
- $extend = MerchantExtendService::getByMerchantId($merchantId);
|
|
|
- $config = [
|
|
|
- //应用ID,您的APPID。
|
|
|
- 'app_id' => $extend['alipayPId'],
|
|
|
- //商户私钥,您的原始格式RSA私钥
|
|
|
- 'merchant_private_key' => $extend['alipayKey'],
|
|
|
- //异步通知地址
|
|
|
- 'notify_url' => Yii::$app->params['frontUrl'] . "/notice/alipay-async",
|
|
|
- //同步跳转
|
|
|
- 'return_url' => "",
|
|
|
- //编码格式
|
|
|
- 'charset' => "UTF-8",
|
|
|
- //签名方式
|
|
|
- 'sign_type' => "RSA2",
|
|
|
- //支付宝网关
|
|
|
- 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
|
|
|
- //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
|
|
|
- 'alipay_public_key' => $extend['alipayPublicKey'],
|
|
|
- ];
|
|
|
-
|
|
|
- require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
|
|
|
- require_once($alipayWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
|
|
|
-
|
|
|
- $arr = $_POST;
|
|
|
- $alipaySevice = new \AlipayTradeService($config);
|
|
|
- $alipaySevice->writeLog(var_export($_POST, true));
|
|
|
- $result = $alipaySevice->check($arr);
|
|
|
- Yii::info('check:' . $result);
|
|
|
- if ($result) {//验证成功
|
|
|
- $tradeNo = $_POST['trade_no'];//支付宝交易号
|
|
|
- $tradeStatus = $_POST['trade_status'];//交易状态
|
|
|
- $totalFee = $_POST['total_amount'];
|
|
|
- $appId = $_POST['app_id'];
|
|
|
- $passbackParams = $_POST['passback_params'];
|
|
|
- $passbackParams = urldecode($passbackParams);
|
|
|
- parse_str($passbackParams);//接收流水类型、代金劵
|
|
|
- $couponId = isset($couponId) ? $couponId : 0;
|
|
|
- $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
|
|
|
-
|
|
|
- $RequestBuilder = new \AlipayTradeQueryContentBuilder();
|
|
|
- $RequestBuilder->setTradeNo($tradeNo);
|
|
|
- $queryResult = $alipaySevice->Query($RequestBuilder);
|
|
|
- $alipayId = $queryResult->buyer_user_id;
|
|
|
- $alipayAccount = $queryResult->buyer_logon_id;//买家的支付宝帐号,不完整,带*号
|
|
|
- $alipayParams = ['alipayId' => $alipayId, 'alipayAccount' => $alipayAccount];
|
|
|
-
|
|
|
- if (isset($capitalType) == false) {
|
|
|
- Yii::warning('capitalType empty, orderId:' . $orderId);
|
|
|
- util::end();
|
|
|
- }
|
|
|
- if ($config['app_id'] != $appId) {
|
|
|
- Yii::warning('app_id disagree, orderId:' . $orderId . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
|
|
|
- util::end();
|
|
|
- }
|
|
|
- if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
|
|
|
- $callbackParams = [];
|
|
|
- $return = xhPayToolService::alipay($callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $alipayParams);//支付回调流程
|
|
|
- if ($return['code'] == 'A0002') {
|
|
|
- Yii::warning('callback exec and failed,capitalType:' . $capitalType . ' orderId:' . $orderId);
|
|
|
- util::end();
|
|
|
- }
|
|
|
- }
|
|
|
- //请不要修改或删除
|
|
|
- echo "success";
|
|
|
- util::end();
|
|
|
- }
|
|
|
- //请不要修改或删除
|
|
|
- echo "fail";
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
+ public $categoryList;
|
|
|
+
|
|
|
+ //微信支付异步回调
|
|
|
+ public function actionWxCallback()
|
|
|
+ {
|
|
|
+ $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
|
|
|
+ if (empty($postStr)) {
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+ $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
|
|
|
+ if ($postObj->return_code != 'SUCCESS') {
|
|
|
+ Yii::warning('return_code error:' . $postObj->return_code);
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+ $orderId = $postObj->out_trade_no;
|
|
|
+ $total_fee = $postObj->total_fee;
|
|
|
+ $totalFee = $total_fee / 100;
|
|
|
+ $attach = $postObj->attach;
|
|
|
+ //接收流水类型、代金劵
|
|
|
+ parse_str($attach);
|
|
|
+ $couponId = isset($couponId) ? $couponId : 0;
|
|
|
+ //流水类型
|
|
|
+ $capitalType = isset($capitalType) ? $capitalType : null;
|
|
|
+ $wxPayType = isset($wxPayType) ? $wxPayType : 0;
|
|
|
+ if (isset($capitalType) == false) {
|
|
|
+ Yii::warning('capitalType empty,orderId:' . $orderId);
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+ $callbackParams = ['wxPayType' => $wxPayType];
|
|
|
+ $return = xhPayToolService::weixinPay($callbackParams, $orderId, $totalFee, $capitalType, $couponId);//支付回调流程
|
|
|
+ if (isset($return['code']) && $return['code'] == 'A0002') {
|
|
|
+ Yii::warning('callback exec and failed,capitalType:' . $capitalType . ' orderId:' . $orderId);
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+ echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
|
|
|
+ }
|
|
|
+
|
|
|
+ //支付宝异步通知
|
|
|
+ public function actionAlipayCallback()
|
|
|
+ {
|
|
|
+ header("Content-type: text/html; charset=utf-8");
|
|
|
+ $alipayWap = Yii::getAlias("@vendor/alipayWap");
|
|
|
+ $orderSn = $_POST['out_trade_no'];//商户订单号
|
|
|
+ $pay = xhOrderService::getByOrderSn($orderSn);
|
|
|
+ if (empty($pay)) {
|
|
|
+ Yii::warning('没有找到订单:orderSn:' . $orderSn);
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+ $orderId = $pay['id'];//商户订单号
|
|
|
+ $merchantId = isset($pay['merchantId']) ? $pay['merchantId'] : 0;
|
|
|
+ $extend = MerchantExtendService::getByMerchantId($merchantId);
|
|
|
+ $config = [
|
|
|
+ //应用ID,您的APPID。
|
|
|
+ 'app_id' => $extend['alipayPId'],
|
|
|
+ //商户私钥,您的原始格式RSA私钥
|
|
|
+ 'merchant_private_key' => $extend['alipayKey'],
|
|
|
+ //异步通知地址
|
|
|
+ 'notify_url' => Yii::$app->params['frontUrl'] . "/notice/alipay-async",
|
|
|
+ //同步跳转
|
|
|
+ 'return_url' => "",
|
|
|
+ //编码格式
|
|
|
+ 'charset' => "UTF-8",
|
|
|
+ //签名方式
|
|
|
+ 'sign_type' => "RSA2",
|
|
|
+ //支付宝网关
|
|
|
+ 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
|
|
|
+ //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
|
|
|
+ 'alipay_public_key' => $extend['alipayPublicKey'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
|
|
|
+ require_once($alipayWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
|
|
|
+
|
|
|
+ $arr = $_POST;
|
|
|
+ $alipaySevice = new \AlipayTradeService($config);
|
|
|
+ $alipaySevice->writeLog(var_export($_POST, true));
|
|
|
+ $result = $alipaySevice->check($arr);
|
|
|
+ Yii::info('check:' . $result);
|
|
|
+ if ($result == false) {
|
|
|
+ //请不要修改
|
|
|
+ echo "fail";
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证成功后续
|
|
|
+ $tradeNo = $_POST['trade_no'];//支付宝交易号
|
|
|
+ $tradeStatus = $_POST['trade_status'];//交易状态
|
|
|
+ $totalFee = $_POST['total_amount'];
|
|
|
+ $appId = $_POST['app_id'];
|
|
|
+ $passbackParams = $_POST['passback_params'];
|
|
|
+ $passbackParams = urldecode($passbackParams);
|
|
|
+ parse_str($passbackParams);//接收流水类型、代金劵
|
|
|
+ $couponId = isset($couponId) ? $couponId : 0;
|
|
|
+ $capitalType = isset($capitalType) ? $capitalType : null;//流水类型
|
|
|
+
|
|
|
+ $RequestBuilder = new \AlipayTradeQueryContentBuilder();
|
|
|
+ $RequestBuilder->setTradeNo($tradeNo);
|
|
|
+ $queryResult = $alipaySevice->Query($RequestBuilder);
|
|
|
+ $alipayId = $queryResult->buyer_user_id;
|
|
|
+ $alipayAccount = $queryResult->buyer_logon_id;//买家的支付宝帐号,不完整,带*号
|
|
|
+ $alipayParams = ['alipayId' => $alipayId, 'alipayAccount' => $alipayAccount];
|
|
|
+
|
|
|
+ if (isset($capitalType) == false) {
|
|
|
+ Yii::warning('capitalType empty, orderId:' . $orderId);
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+ if ($config['app_id'] != $appId) {
|
|
|
+ Yii::warning('app_id disagree, orderId:' . $orderId . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+ if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
|
|
|
+ $callbackParams = [];
|
|
|
+ $return = xhPayToolService::alipay($callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $alipayParams);//支付回调流程
|
|
|
+ if ($return['code'] == 'A0002') {
|
|
|
+ Yii::warning('callback exec and failed,capitalType:' . $capitalType . ' orderId:' . $orderId);
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //请不要修改
|
|
|
+ echo "success";
|
|
|
+ }
|
|
|
+
|
|
|
}
|