$name, 'out_trade_no' => $out_trade_no, 'total_fee' => $total_fee*100, 'notify_url' => $notify_url, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 'trade_type' => $trade_type, // 请对应换成你的支付方式对应的值类型 ); if($trade_type != 'APP'){ $parameter['openid'] = $openid; } $result = $app->order->unify($parameter); $jssdk = $app->jssdk; $config = $jssdk->sdkConfig($result['prepay_id']); return $config; }catch (Exception $e){ return false; } } /** * 商品订单支付回调 */ public function goodsOrderNotify() { $app = Factory::payment(config('app.wx_pay')); $response = $app->handlePaidNotify(function ($message, $fail) { $this->payResultLog($message,'goods_order'); // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单 $pay_no = $message['out_trade_no']; $order_info = Db::name('goods_order')->where('pay_no',$pay_no)->find(); // 如果订单不存在 或者 订单已经支付过了 告诉微信,我已经处理完了,订单没找到,别再通知我了 if ($message['result_code'] == 'SUCCESS') { // return_code 表示通信状态,不代表支付状态 Db::startTrans(); $goods_info = Db::table('store_goods')->find($order_info['goods_id']); $collect_num = Db::table('goods_collect') ->where(['goods_id'=>$goods_info['id']]) ->where('status','in',[1,3])->count(); $serial = intval($collect_num) + 1; $user_info =Db::table('store_member')->find( $order_info['uid']); $collect_info = [ 'user_id'=> $order_info['uid'], 'goods_id'=> $order_info['goods_id'], 'goods_cover'=> $order_info['goods_cover'], 'goods_name'=> $order_info['goods_name'], 'serial' => $serial, 'from_id' => $order_info['id'], 'sc_name' =>$user_info['name'],//收藏者 'issuer' =>$goods_info['issuer'],//发行方 'framer' =>$goods_info['goods_auth'],//framer 'coll_intro'=>$goods_info['coll_intro'],//作品介绍 ]; $collect_info = array_merge($collect_info,get_goods_hash($order_info['uid'],$goods_info['id'],$serial)); Db::table('goods_collect')->insert($collect_info); goods_sell_info($goods_info,$order_info['uid'],$order_info['id']); $res = Db::table('goods_order')->where('id',$order_info['id'])->update(['pay_time'=>date('Y-m-d H:i:s'),'pay_state'=>1,'pay_type'=>1,'status'=>1]); if(!$res){ Db::rollback(); }else{ Db::commit(); } return true; // 返回处理完成 } else if ($message['return_code'] != 'SUCCESS'){ return $fail('通信失败,请稍后再通知我'); } }); $response->send(); } /** *元石充值 */ public function crystalRecharge() { $app = Factory::payment(config('app.wx_pay')); $response = $app->handlePaidNotify(function ($message, $fail) { $this->payResultLog($message,'crystal_order'); // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单 $pay_no = $message['out_trade_no']; $order_info = Db::name('crystal_order')->where('pay_no',$pay_no)->find(); // 如果订单不存在 或者 订单已经支付过了 告诉微信,我已经处理完了,订单没找到,别再通知我了 if ($message['result_code'] == 'SUCCESS') { // return_code 表示通信状态,不代表支付状态 Db::startTrans(); $user_info = Db::table('store_member')->find($order_info['uid']); // 更新会员余额 Db::table('store_member')->where('id',$order_info['uid'])->update(['crystal'=>bcadd($user_info['crystal'],$order_info['crystal'],2)]); // 元石明细 crystal_log($order_info['uid'],$order_info['crystal'],'元石充值',1,$order_info['id']); // 更新订单状态 $res = Db::table('crystal_order')->where('id',$order_info['id']) ->update(['pay_at'=>date('Y-m-d H:i:s'),'pay_state'=>1,'pay_type'=>1,'status'=>1]); if(!$res){ Db::rollback(); }else{ Db::commit(); } return true; // 返回处理完成 } else if ($message['return_code'] != 'SUCCESS'){ return $fail('通信失败,请稍后再通知我'); } }); $response->send(); } /** * 记录支付日志 * @param $message * @param $table_name */ public function payResultLog($message,$table_name) { // 回调记录 $ret_arr = []; $ret_arr['transaction_id'] = isset($message['transaction_id']) ?$message['transaction_id']: ''; $ret_arr['trade_no'] = isset($message['out_trade_no']) ?$message['out_trade_no']: ''; $ret_arr['return_code'] = isset($message['return_code']) ?$message['return_code']: ''; $ret_arr['result_code'] = isset($message['result_code']) ?$message['result_code']: ''; $ret_arr['create_at'] = date('Y-m-d H:i:s'); $ret_arr['order_table'] = $table_name; $ret_arr['result'] = json_encode($message); Db::table('order_pay_result')->insert($ret_arr); } }