appID = $payment['pay_routine_appid'] ?? ''; $params->mch_id = $payment['pay_routine_mchid'] ?? ''; $params->key = $payment['pay_routine_key'] ?? ''; $params->keyPath = realpath('.' . $payment['pay_routine_client_key']); $params->certPath = realpath('.' . $payment['pay_routine_client_cert']); return $params; } /** * 付款到微信零钱 * * 文档见 (https://doc.yurunsoft.com/PaySDK/112) * * NOTICE: 本函数只是调用微信 API,并未进行业务逻辑处理。 * * @param int $openid: wechat user openid * @param string $trade_no: 付款订单号,平台自定义 * @param int $amount: 金额,单位为分 * @param string $desc: 订单描述 * @param string $realname: 收款放真实姓名, 参数 check_name 为 FORCE_CHECK 时使用。 * * @return (bool, int, string) (是否成功,错误代码,错误信息) * * TODO: 微信付款升级为 V3(https://wechatpay-api.gitbook.io/wechatpay-api-v3/wei-xin-zhi-fu-api-v3-jie-kou-gui-fan) * 本功能使用 Yurunsoft/PaySDK 也已支持 V3 (2021/11/28),但申请微信支付时未申请微信 V3 相关 Key。等待升级使用 V3 协议,或再做一个函数 */ public static function toWeixin($openid, $trade_no, $amount, $desc='', $realname='') { try { $caller_ip = Config::get('app.server_ip', '127.0.0.1'); $params = self::getWeixinParams(); $sdk = new SDK($params); $req = new Request(); $req->partner_trade_no = $trade_no; $req->openid = $openid; $req->check_name = 'NO_CHECK'; $req->re_user_name = $realname; $req->amount = intval(bcmul($amount, 100, 0)); $req->desc = $desc; $req->spbill_create_ip = $caller_ip; // 调用接口的机器IP, 这个可能微信用于验证 $res = $sdk->execute($req); return [ $sdk->checkResult($res), $sdk->getErrorCode($res), $sdk->getError($res), ]; } catch (\Exception $e) { Log::warning('exception:' . $e->getMessage()); return [false, $e->getCode(), $e->getMessage()]; } } /** * 通过微信支付付款到银行卡 */ public static function toBankByWeixin() { try { } catch (\Exception $e) { } } /** * 付款到支付宝 */ public static function toAlipay() { } /** * 通过支付宝付款到银行卡 */ public static function toBankByAlipay() { } }