怎么下载,怎么配置就不说了
文件目录:addons\epay\library\Service.php
构造函数加,用V3 set_addon_config('epay', ['version'=>'v3'], false);
//退款 public static function refunds($orderdata,$type, $config = []) { $type = strtolower($type); if (!in_array($type, ['wechat', 'alipay'])) { return false; } try { $config = self::getConfig($type); $pay = $type == 'wechat' ? Pay::wechat($config) : Pay::alipay($config); $result = $pay->refund($orderdata); } catch (Exception $e) { return $e->getMessage(); } //使用重写的Response类、RedirectResponse、Collection类 $return_arr = $result->toArray(); return $return_arr; }
调用:
$notifyurl = local_domain()."/api/wxpays/refundcb"; $orders = [ 'out_trade_no' => $order['order_sn'], 'out_refund_no' => $row['refund_sn'], 'notify_url' => $notifyurl, 'amount' => [ 'refund' => $row['refund_amount'] * 100, 'total' => $order['order_amount'] * 100, 'currency' => 'CNY', ], ]; $result = \addons\epay\library\Service::refunds($orders,'wechat');
回调解密:
/** * 会员微信支付回调 * */ public function refundcb(){ $datas = file_get_contents("php://input"); $re = $this->payment_notify(json_decode($datas,true)); $order_refund = db("order_refund")->where("refund_sn", $re['out_refund_no'])->find(); if($order_refund['refund_status'] == 'SUCCESS'){ $order_refund = db("order_refund")->where("refund_sn", $re['out_refund_no'])->update(['refund_status' => 1, 'refund_msg' => $re['user_received_account']]); }else{ $order_refund = db("order_refund")->where("refund_sn", $re['out_refund_no'])->update(['refund_status' => 2, 'refund_msg' => $re['user_received_account']]); } // array(9) { // ["mchid"] => string(10) "16503973" // ["out_trade_no"] => string(18) "2023082008406397" // ["transaction_id"] => string(28) "42000019512023083246790610" // ["out_refund_no"] => string(12) "wx169332946" // ["refund_id"] => string(29) "503014069320230900842130470" // ["refund_status"] => string(7) "SUCCESS" // ["success_time"] => string(25) "2023-08-29T23:12:34+08:00" // ["amount"] => array(4) { // ["total"] => int(2) // ["refund"] => int(1) // ["payer_total"] => int(2) // ["payer_refund"] => int(1) // } // ["user_received_account"] => string(18) "支付用户零钱" // } echo json_encode(['code' => 'SUCCESS', 'message' => '成功']); } /* * 微信支付V3回调解密 * */ public function payment_notify($input_data) { $key = 'f940d7***********d5fd49';//商户平台设置的api v3 密码 $text = base64_decode($input_data['resource']['ciphertext']); //解密 /* =========== 使用V3支付需要PHP7.2.6安装sodium扩展才能进行解密参数 ================ */ $str = sodium_crypto_aead_aes256gcm_decrypt($text, $input_data['resource']['associated_data'], $input_data['resource']['nonce'], $key); $res = json_decode($str, true); return $res; }