|
@@ -0,0 +1,86 @@
|
|
|
+<?php
|
|
|
+namespace app\home\controller;
|
|
|
+
|
|
|
+use think\Controller;
|
|
|
+use think\Db;
|
|
|
+use app\user\model\PayPlugin;
|
|
|
+use app\user\model\User;
|
|
|
+use app\user\model\UserPay;
|
|
|
+
|
|
|
+class Pay extends Controller{
|
|
|
+ private $payPluginModel, $userModel;
|
|
|
+
|
|
|
+ public function _initialize(){
|
|
|
+
|
|
|
+ $this->payPluginModel= new PayPlugin();
|
|
|
+ $this->userModel = new User();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function pay(){
|
|
|
+ $data = decode($this->request->post());
|
|
|
+
|
|
|
+ $data['t'] = 1;
|
|
|
+ $data['i'] = 1;
|
|
|
+ $data['u'] = 324234;
|
|
|
+
|
|
|
+ $ipaInfo = Db::name('iap_config')->where(['id'=>$data['i']])->find();
|
|
|
+ if(empty($ipaInfo)) dir(json(['error'=>1111]));
|
|
|
+
|
|
|
+ $plugin = $this->payPluginModel->getPayPluginByType($data['t']);
|
|
|
+ if(empty($plugin)) dir(json(['error'=>1111]));
|
|
|
+
|
|
|
+ $biz_content = $this->getAliTradeInfo($ipaInfo, $data['u']);
|
|
|
+ $val = $this->getAliPayInfo($plugin, $biz_content);
|
|
|
+ print_r($val);
|
|
|
+ exit;
|
|
|
+
|
|
|
+ return http_build_query($val);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function notify(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getAliTradeInfo($ipa, $user){
|
|
|
+ $content = [];
|
|
|
+
|
|
|
+ $content['subject'] = "玩家充值";
|
|
|
+ $content['out_trade_no'] = $tradeNo = 'D'.getId();
|
|
|
+ $content['total_amount'] = $ipa['price'];
|
|
|
+ $content['product_code'] = 'QUICK_MSECURITY_PAY';
|
|
|
+ $content['timeout_express'] = '90m';
|
|
|
+ $content['body'] = $ipa['desc'];
|
|
|
+
|
|
|
+// $userPay = new UserPay();
|
|
|
+// $userPay->add(['user_id'=>$user, 'cost'=>$ipa['price'], 'pay_id'=>$ipa['id'], 'out_trade_no'=>$tradeNo]);
|
|
|
+
|
|
|
+ return json_encode($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getAliPayInfo($plugin, $biz_content){
|
|
|
+ $params = [];
|
|
|
+
|
|
|
+ $params['gatewayUrl'] = "https://openapi.alipaydev.com/gateway.do";
|
|
|
+
|
|
|
+ $params['app_id'] = $plugin['appid'];
|
|
|
+ $params['method'] = 'alipay.trade.app.pay';
|
|
|
+ $params['format'] = "json";
|
|
|
+ $params['charset'] = "UTF-8";
|
|
|
+ $params['version'] = "1.0";
|
|
|
+ $params['timestamp'] = getCurrentTime();
|
|
|
+ $params['sign_type'] = "RSA2";
|
|
|
+ $params['notify_url'] = 'http://'.$_SERVER['SERVER_NAME']._PHP_FILE_.'/'.$this->request->module().'/'.$this->request->controller().'/notify';
|
|
|
+ $params['biz_content'] = $biz_content;
|
|
|
+
|
|
|
+ ksort($params);
|
|
|
+
|
|
|
+ $params['sign'] = aliSign($plugin['private_key'], getAliSignContent($params));
|
|
|
+
|
|
|
+ foreach ($params as &$value) {
|
|
|
+ $value = characet($value, $params['charset']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|