更新
This commit is contained in:
parent
3031767859
commit
54d5b3ae56
@ -4,6 +4,8 @@ namespace app\api\controller;
|
|||||||
|
|
||||||
use app\admin\validate\tools\GenerateTableValidate;
|
use app\admin\validate\tools\GenerateTableValidate;
|
||||||
use app\admin\logic\tools\GeneratorLogic;
|
use app\admin\logic\tools\GeneratorLogic;
|
||||||
|
use app\common\service\pay\PayService;
|
||||||
|
use app\common\service\wechat\WeChatOaService;
|
||||||
|
|
||||||
class IndexController extends BaseApiController
|
class IndexController extends BaseApiController
|
||||||
{
|
{
|
||||||
@ -11,7 +13,43 @@ class IndexController extends BaseApiController
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
d(2);
|
$template=[
|
||||||
|
'touser'=>'ocqhF6UfFQXE-SbzbP5YVQJlQAh0',
|
||||||
|
'template_id'=>'hfvTch-DcP_UQ83VkD6Z-eMimeRrK8P8zpWC9j2dOKc',
|
||||||
|
'miniprogram'=>'data',
|
||||||
|
'appid'=>'wxdee751952c8c2027',
|
||||||
|
'pagepath'=>'pages/index/index',
|
||||||
|
'data'=>[
|
||||||
|
'thing2' => ['value'=>'圆珠笔采购订单'],
|
||||||
|
'time6' => ['value'=>date('Y-m-d H:i:s')],
|
||||||
|
'thing4' =>['value'=>'张三'],
|
||||||
|
'phone_number5' =>['value'=>18982406440],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$token='80_u14-Yey-hmXxx-GPD0Pk8X0l_0OQ0B8U-VWNw8h9cs3RYCefviQMK_idliIZ5qUvBCcfuW7NPUUL3CTCB87gJgTFpwRWULWG-nqq9gTDxtX_Su7EjVcW9QJsjuYENNbAAAQZZ';
|
||||||
|
$url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token;
|
||||||
|
$a=new WeChatOaService();
|
||||||
|
d($a->getClient()->post($url,$template));
|
||||||
|
$order = [
|
||||||
|
'description' => '测试 - yansongda - 1',
|
||||||
|
'out_trade_no' => time().'',
|
||||||
|
'payer' => [
|
||||||
|
'auth_code' => '123456789123456789'
|
||||||
|
],
|
||||||
|
'amount' => [
|
||||||
|
'total' => 1,
|
||||||
|
],
|
||||||
|
'scene_info' => [
|
||||||
|
'device_id' => '013467007045764',
|
||||||
|
'device_ip' => '128.0.0.1',
|
||||||
|
"store_info"=>[
|
||||||
|
"id" => "0001",
|
||||||
|
"out_id" => "A1111"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
d($a->wechat->pos($order));
|
||||||
return json(['msg' =>create_password(123456, '11d3')]);
|
return json(['msg' =>create_password(123456, '11d3')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,207 +69,5 @@ class WeChatPayService extends BasePayService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 发起微信支付统一下单
|
|
||||||
* @param $from
|
|
||||||
* @param $order
|
|
||||||
* @return array|false|string
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2021/8/4 15:05
|
|
||||||
*/
|
|
||||||
public function pay($from, $order)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
switch ($this->terminal) {
|
|
||||||
case UserTerminalEnum::WECHAT_MMP:
|
|
||||||
$config = WeChatConfigService::getMnpConfig();
|
|
||||||
$result = $this->jsapiPay($from, $order, $config['app_id']);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new \Exception('支付方式错误');
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'config' => $result,
|
|
||||||
'pay_way' => PayEnum::WECHAT_PAY
|
|
||||||
];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->setError($e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes jsapiPay
|
|
||||||
* @param $from
|
|
||||||
* @param $order
|
|
||||||
* @param $appId
|
|
||||||
* @return mixed
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2023/2/28 12:12
|
|
||||||
*/
|
|
||||||
public function jsapiPay($from, $order, $appId)
|
|
||||||
{
|
|
||||||
$response = $this->app->getClient()->postJson("v3/pay/transactions/jsapi", [
|
|
||||||
"appid" => $appId,
|
|
||||||
"mchid" => $this->config['mch_id'],
|
|
||||||
"description" => $this->payDesc($from),
|
|
||||||
"out_trade_no" => $order['pay_sn'],
|
|
||||||
"notify_url" => $this->config['notify_url'],
|
|
||||||
"amount" => [
|
|
||||||
"total" => intval($order['actual'] * 100),
|
|
||||||
],
|
|
||||||
"payer" => [
|
|
||||||
"openid" => $this->auth['openid']
|
|
||||||
],
|
|
||||||
'attach' => $from
|
|
||||||
]);
|
|
||||||
|
|
||||||
$result = $response->toArray(false);
|
|
||||||
$this->checkResultFail($result);
|
|
||||||
return $this->getPrepayConfig($result['prepay_id'], $appId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 退款
|
|
||||||
* @param array $refundData
|
|
||||||
* @return mixed
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2023/2/28 16:53
|
|
||||||
*/
|
|
||||||
public function refund(array $refundData)
|
|
||||||
{
|
|
||||||
$response = $this->app->getClient()->postJson('v3/refund/domestic/refunds', [
|
|
||||||
'transaction_id' => $refundData['transaction_id'],
|
|
||||||
'out_refund_no' => $refundData['refund_sn'],
|
|
||||||
'amount' => [
|
|
||||||
'refund' => intval($refundData['refund_amount'] * 100),
|
|
||||||
'total' => intval($refundData['total_amount'] * 100),
|
|
||||||
'currency' => 'CNY',
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
$result = $response->toArray(false);
|
|
||||||
$this->checkResultFail($result);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 查询退款
|
|
||||||
* @param $refundSn
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2023/3/1 11:16
|
|
||||||
*/
|
|
||||||
public function queryRefund($refundSn)
|
|
||||||
{
|
|
||||||
$response = $this->app->getClient()->get("v3/refund/domestic/refunds/{$refundSn}");
|
|
||||||
return $response->toArray(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 支付描述
|
|
||||||
* @param $from
|
|
||||||
* @return string
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2023/2/27 17:54
|
|
||||||
*/
|
|
||||||
public function payDesc($from)
|
|
||||||
{
|
|
||||||
$desc = [
|
|
||||||
'order' => '商品',
|
|
||||||
'recharge' => '充值',
|
|
||||||
];
|
|
||||||
return '商品';//$desc[$from] ?? '商品';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 捕获错误
|
|
||||||
* @param $result
|
|
||||||
* @throws \Exception
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2023/2/28 12:09
|
|
||||||
*/
|
|
||||||
public function checkResultFail($result)
|
|
||||||
{
|
|
||||||
if (!empty($result['code']) || !empty($result['message'])) {
|
|
||||||
throw new \Exception('微信:'. $result['code'] . '-' . $result['message']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 预支付配置
|
|
||||||
* @param $prepayId
|
|
||||||
* @param $appId
|
|
||||||
* @return mixed[]
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2023/2/28 17:38
|
|
||||||
*/
|
|
||||||
public function getPrepayConfig($prepayId, $appId)
|
|
||||||
{
|
|
||||||
return $this->app->getUtils()->buildBridgeConfig($prepayId, $appId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 支付回调
|
|
||||||
* @return \Psr\Http\Message\ResponseInterface
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
||||||
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
|
||||||
* @throws \ReflectionException
|
|
||||||
* @throws \Throwable
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2023/2/28 14:20
|
|
||||||
*/
|
|
||||||
public function notify()
|
|
||||||
{
|
|
||||||
$config = Config::get('payment');
|
|
||||||
Pay::config($config);
|
|
||||||
$result = Pay::wechat()->callback(request()->post());
|
|
||||||
d($result);
|
|
||||||
// Log::error(json_encode(Request()->post()));
|
|
||||||
// $server = $this->app->getServer();
|
|
||||||
// // 支付通知
|
|
||||||
// $server->handlePaid(function (Message $message) {
|
|
||||||
// if ($message['trade_state'] === 'SUCCESS') {
|
|
||||||
// $extra['transaction_id'] = $message['transaction_id'];
|
|
||||||
// $attach = $message['attach'];
|
|
||||||
// $message['out_trade_no'] = mb_substr($message['out_trade_no'], 0, 18);
|
|
||||||
// switch ($attach) {
|
|
||||||
// case 'cashierclass':
|
|
||||||
// $order = Cashierclass::where(['number' => $message['out_trade_no']])->findOrEmpty();
|
|
||||||
// if($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// PayNotifyLogic::handle('cashierclass', $message['out_trade_no'], $extra);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // 退款通知
|
|
||||||
// $server->handleRefunded(function (Message $message) {
|
|
||||||
// return true;
|
|
||||||
// });
|
|
||||||
// return $server->serve();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -51,7 +51,14 @@ class WeChatOaService
|
|||||||
{
|
{
|
||||||
return $this->app->getServer();
|
return $this->app->getServer();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @notes 获取微信客户端
|
||||||
|
* @date 2023/2/27 14:22
|
||||||
|
*/
|
||||||
|
public function getClient()
|
||||||
|
{
|
||||||
|
return $this->app->getClient();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 配置
|
* @notes 配置
|
||||||
|
Loading…
x
Reference in New Issue
Block a user