|
@@ -8,6 +8,7 @@ use app\models\user\UserBill;
|
|
|
use app\models\user\WechatUser;
|
|
|
use app\admin\model\order\StoreOrder as AdminStoreOrder;
|
|
|
use crmeb\services\MiniProgramService;
|
|
|
+use crmeb\services\SystemConfigService;
|
|
|
use crmeb\services\WechatService;
|
|
|
|
|
|
/**
|
|
@@ -91,6 +92,48 @@ class OrderRepository
|
|
|
return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), '', 'MWEB');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 微信app支付
|
|
|
+ * @param $order
|
|
|
+ * @param string $field
|
|
|
+ * @return array|string
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public static function appPay($order, string $field = 'order_id')
|
|
|
+ {
|
|
|
+ if (is_string($order))
|
|
|
+ $orderInfo = StoreOrder::where($field, $order)->find();
|
|
|
+ else
|
|
|
+ $orderInfo = $order;
|
|
|
+ if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
|
|
|
+ if ($orderInfo['paid']) exception('支付已支付!');
|
|
|
+ if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
|
|
|
+ $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
|
|
|
+ $site_name = sys_config('site_name');
|
|
|
+ $wechat = SystemConfigService::more(['weixin_open_appid', 'weixin_open_appsecret'], true);
|
|
|
+ $payment = SystemConfigService::more(['pay_weixin_mchid', 'pay_weixin_client_cert', 'pay_weixin_client_key', 'pay_weixin_key', 'pay_weixin_open'], true);
|
|
|
+ if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
|
|
|
+ $config = array(
|
|
|
+ 'appid' => $wechat['weixin_open_appid'], //填写高级调用功能的app id
|
|
|
+ 'appsecret' => $wechat['weixin_open_appsecret'], //填写高级调用功能的app secret
|
|
|
+ 'mchid' => $payment['pay_weixin_mchid'], //商户id
|
|
|
+ 'key' => $payment['pay_weixin_key'], //填写你设定的key
|
|
|
+ 'sslcert_path' => realpath('.' . $payment['pay_weixin_client_cert']),
|
|
|
+ 'sslkey_path' => realpath('.' . $payment['pay_weixin_client_key']),
|
|
|
+ 'transfer_rsa_public_path' => '', //企业转账到银行卡rsa公钥证书文件路径
|
|
|
+ );
|
|
|
+ $wechatpay = new \JiaLeo\Payment\Wechatpay\AppPay($config);
|
|
|
+ $pay_data = [
|
|
|
+ 'body' => StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), //内容
|
|
|
+ 'attach' => 'product', //商家数据包
|
|
|
+ 'out_trade_no' => $orderInfo['order_id'], //商户订单号
|
|
|
+ 'total_fee' => bcmul($orderInfo['pay_price'], 100, 0), //支付价格(单位:分)
|
|
|
+ 'notify_url' => sys_config('site_url') . '/api/wechat/notify', //后台回调地址
|
|
|
+ ];
|
|
|
+ $url = $wechatpay->handle($pay_data);
|
|
|
+ return $url;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 用户确认收货
|
|
|
* @param $order
|