From 804ca561a3011b66c59e490500a35001a96ab4f2 Mon Sep 17 00:00:00 2001 From: xuyu <1272542526@qq.com> Date: Mon, 13 May 2024 11:11:13 +0800 Subject: [PATCH] xg --- application/wap/controller/Special.php | 24 +++++++----- application/wap/model/store/StoreOrder.php | 45 ++++++++++++++++++---- extend/service/WechatService.php | 3 +- vendor/overtrue/wechat/src/Payment/API.php | 3 +- 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/application/wap/controller/Special.php b/application/wap/controller/Special.php index 1ccb9649..d8007e0c 100755 --- a/application/wap/controller/Special.php +++ b/application/wap/controller/Special.php @@ -194,7 +194,7 @@ class Special extends AuthController if ($order->total_num == $order->gift_count) return JsonService::fail('礼物已被领取完'); } $special = SpecialModel::getOneSpecial($this->uid, $id); - + if ($special === false) return JsonService::fail(SpecialModel::getErrorInfo('无法访问')); $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0; if (!isset($special['special'])) $this->failed('专题信息未获得', Url::build('index/index')); @@ -1108,16 +1108,18 @@ class Special extends AuthController { return $model->where(['order_id' => $orderId, 'paid' => 1, 'uid' => $this->uid])->count(); } + /** * 阅卷订单 * [create_marking_papers_order description] * @param [type] $data_id [description] * @param [type] $payType [description] - * @param string $from [description] + * @param string $from [description] * @param [type] $returnUrl [description] * @return [type] [description] */ - public function create_marking_papers_order($data_id, $payType, $from = 'weixin', $returnUrl){ + public function create_marking_papers_order($data_id, $payType, $from = 'weixin', $returnUrl) + { $testPaper = TestPaper::PreExercisesWhere()->find($test_id); if (!$testPaper) return JsonService::status('ORDER_ERROR', '购买的试卷不存在'); $order = TestPaperOrder::createTestPaperOrder($testPaper, $this->uid, $payType); @@ -1201,6 +1203,7 @@ class Special extends AuthController return JsonService::fail(TestPaperOrder::getErrorInfo('订单生成失败!')); } } + /**创建试卷支付订单 * @param $test_id * @param $payType @@ -1950,7 +1953,7 @@ class Special extends AuthController $is_member = isset($this->userInfo['level']) ? $this->userInfo['level'] : 0; $my = SpecialModel::getMyGradeList(1, 4, $this->uid, $is_member, 0); //$offlineCourse = (new \app\wap\model\special\OfflineCourse)->order('id desc')->limit(4)->select(); - $activity = EventRegistration::eventRegistrationList(1, 4, "", 0 ,0); + $activity = EventRegistration::eventRegistrationList(1, 4, "", 0, 0); $uid = $this->uid; $hot = SpecialModel::getSpecialList(['grade_id' => 0, 'subject_id' => 0, 'search' => '', 'page' => 1, 'limit' => 4, 'type' => 0, 'uid' => $uid, 'is_hot' => 1]); @@ -2650,11 +2653,12 @@ class Special extends AuthController try { switch ($from) { case 'weixinh5': - $jsConfig = StoreOrder::h5Pay($order); - break; - case 'weixin': - $jsConfig = StoreOrder::jsPay($order); + $jsConfig = StoreOrder::h5Pay($order); +// $jsConfig = StoreOrder::jsPay($order); break; +// case 'weixin': +// $jsConfig = StoreOrder::jsPay($order); +// break; case 'mpweixing': $jsConfig = StoreOrder::WeixinMiniPay($order); break; @@ -2664,7 +2668,9 @@ class Special extends AuthController $info['jsConfig'] = $jsConfig; switch ($from) { case 'weixinh5': - return JsonService::status('wechat_h5_pay', '订单创建成功', $info); + //11 + return JsonService::status('wechat_pay', '订单创建成功', $info); +// return JsonService::status('wechat_h5_pay', '订单创建成功', $info); break; case 'mpweixing': return JsonService::status('WECHAT_ROUTINE_PAY', '订单创建成功', $info); diff --git a/application/wap/model/store/StoreOrder.php b/application/wap/model/store/StoreOrder.php index 0451709b..346ea6c8 100755 --- a/application/wap/model/store/StoreOrder.php +++ b/application/wap/model/store/StoreOrder.php @@ -26,6 +26,7 @@ use service\SystemConfigService; use service\WechatService; use service\WechatTemplateService; use think\Cache; +use think\Log; use think\Url; use traits\ModelTrait; use app\wap\model\user\MemberShip; @@ -586,7 +587,17 @@ class StoreOrder extends ModelBasic if ($orderInfo['paid']) exception('支付已支付!'); if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!'); $openid = WechatUser::uidToOpenid($orderInfo['uid']); - return WechatService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'goods', SystemConfigService::get('site_name')); + $res = MiniProgramService::appPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'goods', SystemConfigService::get('site_name')); + + return [ + 'appid' => $res['appid'], + 'partnerid' => $res['partnerid'], + 'prepayid' => $res['prepayid']['prepay_id'], + 'package'=> $res['package'], + 'noncestr'=> $res['noncestr'], + 'sign' => $res['sign'], + 'timestamp' => $res['timestamp'] + ]; } /** * 微信小程序支付 @@ -647,7 +658,7 @@ class StoreOrder extends ModelBasic $orderInfo = self::where($field, $orderId)->find(); else $orderInfo = $orderId; - + if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!'); if ($orderInfo['paid']) exception('支付已支付!'); if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!'); @@ -684,16 +695,36 @@ class StoreOrder extends ModelBasic */ public static function h5Pay($orderId, $field = 'order_id') { + //11 if (is_string($orderId)) - $orderInfo = self::where($field, $orderId)->find(); + $orderInfo = self::where($field, $orderId)->where('type', 2)->find(); else $orderInfo = $orderId; if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!'); if ($orderInfo['paid']) exception('支付已支付!'); if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!'); - $site_name = SystemConfigService::get('site_name'); - if (!$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称'); - return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_price'], 'goods', self::getSubstrUTf8($site_name . '-商品购买', 30), '', 'MWEB'); + $openid = WechatUser::uidToOpenid($orderInfo['uid']); + $res = MiniProgramService::appPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'goods', SystemConfigService::get('site_name')); + + return [ + 'appid' => $res['appid'], + 'partnerid' => $res['partnerid'], + 'prepayid' => $res['prepayid']['prepay_id'], + 'package'=> $res['package'], + 'noncestr'=> $res['noncestr'], + 'sign' => $res['sign'], + 'timestamp' => $res['timestamp'] + ]; +// if (is_string($orderId)) +// $orderInfo = self::where($field, $orderId)->find(); +// else +// $orderInfo = $orderId; +// if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!'); +// if ($orderInfo['paid']) exception('支付已支付!'); +// if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!'); +// $site_name = SystemConfigService::get('site_name'); +// if (!$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称'); +// return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_price'], 'goods', self::getSubstrUTf8($site_name . '-商品购买', 30), '', 'MWEB'); } /**商品余额支付 @@ -858,7 +889,7 @@ class StoreOrder extends ModelBasic if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!'); $site_name = SystemConfigService::get('site_name'); return (new TouMiniProgramService())->jsPay($orderInfo['order_id'], $orderInfo['pay_price'], 'special', self::getSubstrUTf8($site_name, 30)); - + } /**专题余额支付 diff --git a/extend/service/WechatService.php b/extend/service/WechatService.php index f7fbd10f..a81a2234 100755 --- a/extend/service/WechatService.php +++ b/extend/service/WechatService.php @@ -26,6 +26,7 @@ use EasyWeChat\Message\Voice; use EasyWeChat\Payment\Order; use EasyWeChat\Server\Guard; use EasyWeChat\Support\XML; +use think\Log; use think\Request; use think\Url; @@ -420,7 +421,7 @@ class WechatService $refundAccount = isset($opt['refund_account']) ? $opt['refund_account'] : 'REFUND_SOURCE_UNSETTLED_FUNDS'; try { $res = (self::refund($orderNo, $refundNo, $totalFee, $refundFee, $opUserId, $refundReason, $type, $refundAccount)); - + if ($res->return_code == 'FAIL') exception('退款失败:' . $res->return_msg); if (isset($res->err_code)) exception('退款失败:' . $res->err_code_des); } catch (\Exception $e) { diff --git a/vendor/overtrue/wechat/src/Payment/API.php b/vendor/overtrue/wechat/src/Payment/API.php index 83503bbf..edf5ebda 100755 --- a/vendor/overtrue/wechat/src/Payment/API.php +++ b/vendor/overtrue/wechat/src/Payment/API.php @@ -28,6 +28,7 @@ use EasyWeChat\Core\Exception; use EasyWeChat\Support\Collection; use EasyWeChat\Support\XML; use Psr\Http\Message\ResponseInterface; +use think\Log; /** * Class API. @@ -446,7 +447,7 @@ class API extends AbstractAPI $params['device_info'] = $this->merchant->device_info; $params['nonce_str'] = uniqid(); $params = array_filter($params); - + Log::error("安卓app请求参数:".jsOn_encode($params).' 请求地址:'.$api); $params['sign'] = generate_sign($params, $this->getSignkey($api), 'md5'); $options = array_merge([