支付和退款都須要,這裏的支付寶公鑰(注意:不是應用公鑰,支付寶公鑰在應用公鑰基礎上生成的),和應用的私鑰;json
裏面參數有幾個用到支付回調裏面的參數, 支付流水號,支付者信息,支付登陸者信息;api
public function AlipayLaunchRefund($data){ vendor('Alipay.Sdk.AopClient'); vendor('Alipay.Sdk.SignData'); vendor('Alipay.Sdk.request.AlipayTradeRefundRequest'); $aop = new AopClient(); $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; $configs = D('Configs')->getKeys(['alipay_app_id', 'alipay_public_key', 'alipay_private_key']); $aop->appId = $configs['alipay_app_id']; $privateKey = file_get_contents($configs['alipay_private_key']); $publicKey = file_get_contents($configs['alipay_public_key']); $aop->rsaPrivateKey = $privateKey; $aop->alipayrsaPublicKey = $publicKey; $aop->apiVersion = '1.0'; $aop->signType = 'RSA2'; $aop->postCharset = 'UTF-8'; $aop->format = 'json'; $request = new AlipayTradeRefundRequest(); $refundInfo = [ 'trade_no' => $data['trade_no'], 'out_trade_no' => $data['out_trade_no'], 'fund_change' => $data['fund_change'], 'refund_fee' => $data['price'] / 100, 'refund_amount' => $data['price'] / 100, 'refund_currency' => 'CNY', 'gmt_refund_pay' => date('Y-m-d H:i:s',time()), 'store_name' => '***', 'buyer_logon_id' => $data['buyer_logon_id'], 'buyer_user_id' => $data['buyer_user_id'] ]; $bizcontent = json_encode($refundInfo,true); setlog($refundInfo,[],__METHOD__.'__2222'); $request->setBizContent($bizcontent); $result = $aop->execute($request); setlog($result,[],__METHOD__.'__3333'); $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $resultCode = $result->$responseNode->code; if(!empty($resultCode) && $resultCode == 10000){ $return_data = [ 'num' => 1, 'desc' => '退款成功', 'data' => $result->$responseNode->trade_no ]; } else { $return_data = [ 'num' => -1, 'desc' => $result->$responseNode->sub_msg, ]; } return $return_data; } /*** * 支付成功: * [alipay_trade_refund_response] => stdClass Object ( [code] => 10000 [msg] => Success [buyer_logon_id] => men***@163.com [buyer_user_id] => 2088302399936655 [fund_change] => Y [gmt_refund_pay] => 2019-01-28 15:57:58 [out_trade_no] => AXSD19028110031 [refund_fee] => 0.01 [send_back_fee] => 0.00 [trade_no] => 2019012822001436651021876213 ) [sign] => cd/YzFBzIrkW5m460EGbK4p6VjESCTtuD82I/aUj5YxtIGoUp75ZmwhPehHdPrSsLHvtwz4EVytA07EXftpjz7cV0pPL5gQQtM4WeVTEM1EttWK3lMzvKO9uZYJDrYrj8M5qV3zDk926A8fN8BQMKflu7SaBY7eQ/oGMMKbDDYYw9kRAFAhyFEiOBlP868LxNNA4qGJgOBU385uKO1nOqz9Fg9RlMl352ix8fT0XjXccW5VIaLaxZG3o60kFY4Ki7NhklJ4m+abnxXRfztfoBtvH+nsUuSmUBLvtkHIjaC3PZkarCNDJPoIZG06QThjO6KAzAz8j9sSunC3DiGjd8w== ) * 支付失敗: ( [alipay_trade_refund_response] => stdClass Object ( [code] => 40004 [msg] => Business Failed [sub_code] => ACQ.CURRENCY_NOT_SUPPORT [sub_msg] => 商戶簽約結算產品不支持交易幣種 [refund_fee] => 0.00 [send_back_fee] => 0.00 ) [sign] => AEgIeov88pApGGIYx+FS3/FEJ8CXAD7JjsELdo1ile9sGOuDYJqlTO0BF0hFRJU4NA+xcIGPOatINeDbMMdi4n+VcjUWOdctJc8vYZSldi3UFI6hXt5gyMQS5smDvy5Dywa8lDijBmXpV3l2nJqJWKmr5jYIb3lMkFH4ZQZFnNu6hdPb0VdnIq71pyjoYsLKWFai7gWYiBPuGuV9iPb/0dlNuL3BjoTjd/FKFp/1HFPZ3Wpn2CQ26iqDo5nXlPDQw6YzLy24SuIR7yau6P8ZHvHqXMK9G27gBqJG0Lexa2eo7iJCl05/oxisD1TuFunk4rR41UtXeUouT6Gqg9fjew== ) */