fastadmin 微信支付宝整合插件1.3.0 微信退款
怎么下载,怎么配置就不说了
文件目录: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; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2022-08-30 fastadmin 自定义搜索
2019-08-30 【转】小程序web-view覆盖原生组件