💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
下载小程序支付demo [https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11\_1](https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11_1) ``` <?php namespace app\system\api; use app\common\controller\Common; use app\system\model\SystemUser as UserModel; use app\system\model\SystemCooker as CookerModel; use app\system\model\SystemOrder as OrderModel; use app\system\model\SystemCat as CatModel; use app\system\model\SystemGoods as GoodsModel; use app\system\model\SystemRotation as RrotationModel; use Env; use hisi\Dir; use think\Db as Db; class Wxpay extends Common { /** * 获取厨师个人信息 * @author 橘子俊 <364666827@qq.com> * @return mixed */ public function index() { if(!empty($_GET['cooker_id'])) { $data['data']['code'] = 0; $data['data']['msg'] = CookerModel::where('id', '=', $_GET['cooker_id'])->select(); }else{ $data['data']['code'] = 1; $data['data']['msg'] = '用户id不能为空'; } echo json_encode($data);exit; } /* * 去支付 * @return int * @throws \WxPayException */ public function wxpay(){ // $orderNum = time().rand(10000,99999); if(!empty($_GET['user_id'])){ $userinfo = Db::table('hisi_system_cooker') -> where(['id'=>$_GET['user_id']]) -> find(); } if(!empty($_GET['order_id'])){ $orderInfo = Db::table('hisi_system_goods_order') -> where(['id'=>$_GET['order_id']]) -> find(); }else{ exit; } // $openid = "oIR-q5c-oYEfvhxj8IhY8DtD7kcA"; $openid = $userinfo['open_id']; $money = $orderInfo['total_price']*100;// 订单总金额,单位为分,详见支付金额 // $money = 1000;// 订单总金额,单位为分,详见支付金额 require_once '../extend/wxpay/lib/WxPay.Api.php';//引用类文件 require_once '../extend/wxpay/example/WxPay.Config.php';//引用类文件 require_once '../extend/wxpay/example/WxPay.JsApiPay.php';//引用类文件 //②、统一下单 $tools = new \JsApiPay(); $input = new \WxPayUnifiedOrder(); $input->SetBody("微信支付"); //这里是支付内容 $input->SetAttach('test'); //此处可传值,待支付成功后可取这部分的值 $input->SetOut_trade_no($orderInfo['order_no']); //订单编号 $input->SetTotal_fee($money); //金额 // $input->SetTotal_fee(1); //金额 $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag("test"); // $input->SetNotify_url("http://ceshi.net/Retailapi/Weixinpay/notify");//回调地址 $input->SetNotify_url("https://chushi.yongtantec.com//api.php/system/wxpay/Wxpay/notify");//回调地址 $input->SetTrade_type("JSAPI"); $input->SetOpenid($openid); $config = new \WxPayConfig(); $order = \WxPayApi::unifiedOrder($config, $input); $jsApiParameters = $tools->GetJsApiParameters($order); $data['res'] = $jsApiParameters; echo json_encode($data); } /* *回调地址 */ public function notify(){ //获取返回的xml $testxml = file_get_contents("php://input"); //将xml转化为json格式 $jsonxml = json_encode(simplexml_load_string($testxml, 'SimpleXMLElement', LIBXML_NOCDATA)); //转成数组 $result = json_decode($jsonxml,true); // $myfile = fopen("a.txt", "w") or die("Unable to open file!"); // fwrite($myfile, $jsonxml); // fclose($myfile); // file_put_contents('a.txt',$jsonxml); // --这里是调试方法根目录中test.txt中可查看数据情况 if($result){ //如果成功返回了 if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ file_put_contents('test.txt',$result); $orderSn = $result['out_trade_no']; $transactionId = $result['transaction_id']; $orderIni['order_num'] = $orderSn; $res = Db::table('hisi_system_goods_order')->where(['order_no'=>$orderSn])->find();//查询订单 $userinfo = Db::table('hisi_system_cooker')->where(['id'=>$res['cooker_id']])->find();//查询用户信息 if($res['status'] != 1){ $orderData['transaction_id'] = $transactionId; $res['status'] = 4; $orderData['end_time'] = time(); // $userinfo['balance'] = $userinfo['balance'] + $result['total_fee']/100; Db::table('hisi_system_goods_order')->where(['order_no'=>$orderSn])->save($res); Db::table('hisi_system_cooker')->where(['id'=>$res['user_id']])->save($userinfo); } echo exit('<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>'); } } } } ```