php支付宝支app支付,退款

308 阅读1分钟

支付宝退款

总共有三个配置支付宝公钥 应用公钥 应用私钥
Vendor('alipaysdk.AopSdk');
$aop = new AopClient;
$aop->gatewayUrl = C('ALI_GATE_WAY_URL');
$aop->appId = C('ALI_APPID');
$aop->rsaPrivateKey = C('ALI_RSAPRIVATEKEY');
$aop->alipayrsaPublicKey = C('ALI_NOTIFY_RSAPRIVATEKEY');//这个是支付宝的公钥
$aop->apiVersion = '1.0';
$aop->signType = "RSA2";
$aop->charset = "utf-8";
$aop->format = "json";
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
$request = new AlipayTradeRefundRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数
$bizcontent = "{\"out_trade_no\":\"" . $wxpay_info['out_trade_no'] . "\","
        . "\"refund_amount\": \"" . $wxpay_info['money'] . "\","
        . "\"refund_reason\":\"预约订单退款\""//注意这里不能有逗号
        . "}";
$request->setBizContent($bizcontent);
$result = $aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
$refund_fee = $result->$responseNode->refund_fee;

支付宝app支付

Vendor('alipaysdk.AopSdk');
$aop = new AopClient;
$aop->gatewayUrl = C('ALI_GATE_WAY_URL');
$aop->appId = C('ALI_APPID');
$aop->rsaPrivateKey = C('ALI_RSAPRIVATEKEY');//应用私钥
$aop->format = "json";
$aop->charset = "UTF-8";
$aop->signType = "RSA2";
$aop->alipayrsaPublicKey = C('ALI_RSAPRUBLICKEY');//应用公钥
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
$request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数
$bizcontent = "{\"body\":\"" . $body . "\","
        . "\"subject\": \"" . $subject . "\","
        . "\"out_trade_no\": \"" . $out_trade_no . "\","
        . "\"timeout_express\": \"30m\","
        . "\"total_amount\": \"" . $money . "\","
        . "\"product_code\":\"QUICK_MSECURITY_PAY\""
        . "}";
$request->setNotifyUrl($notify_url);
$request->setBizContent($bizcontent);
//这里和普通的接口调用不同,使用的是sdkExecute
$response = $aop->sdkExecute($request);