点开工具、字典、anything


2019-08-10

<h1>微信支付</h1> <p>使用easywechat,统一下单</p> <pre><code class="language-php">$payconfig = Di::getDefault()-&gt;get('config')-&gt;payconfig; $param = [ 'body' =&gt; $title, //标题 'out_trade_no' =&gt; $o_number, //订单编号 'total_fee' =&gt; $price, //总价(单位:分) 'notify_url' =&gt; empty($notifyUrl) ? $payconfig-&gt;notify_url : $notifyUrl, //回调地址 'trade_type' =&gt; $tradeType, //支付方式 'openid' =&gt; $openid, //支付用户openid ]; $config = [ 'app_id' =&gt; $payconfig-&gt;pay_appid, //支付小程序appid 'mch_id' =&gt; $payconfig-&gt;pay_mchid, //商户号 'key' =&gt; $payconfig-&gt;pay_key, //密钥 ]; $app = Factory::payment($config); $unify = $app-&gt;order-&gt;unify($param); if (!isset($unify['result_code']) || $unify['result_code'] != 'SUCCESS') { $payLog-&gt;error(json_encode($unify, JSON_UNESCAPED_UNICODE)); return false; } $bridgeConfig = $app-&gt;jssdk-&gt;bridgeConfig($unify['prepay_id']); return json_decode($bridgeConfig, true);</code></pre> <p>回调处理</p> <pre><code class="language-php">$config = [ 'app_id' =&gt; $payconfig-&gt;pay_appid, //支付小程序appid 'mch_id' =&gt; $payconfig-&gt;pay_mchid, //商户号 'key' =&gt; $payconfig-&gt;pay_key, //密钥 ]; $app = Factory::payment($config); $response = $app-&gt;handlePaidNotify(function ($message, $fail) { $payLog = Di::getDefault()-&gt;getShared('pay_logger'); try { if (!isset($message['return_code']) || $message['return_code'] !== 'SUCCESS') { throw new \Exception('支付回调信息有误(param)' . json_encode($message, JSON_UNESCAPED_UNICODE)); } if ($message['result_code'] == 'SUCCESS') { } elseif ($message['result_code'] == 'FAIL') { } } } catch (\Exception $e) { return $fail('通信失败,请稍后再通知我'); } return true; }); $response-&gt;send(); exit;</code></pre>

页面列表

ITEM_HTML