payPluginModel= new PayPlugin(); $this->userModel = new User(); } public function pay(){ $data = decode($this->request->post()); // $data['i'] = 'com.dashgame.garden.packone'; // $data['t'] = 1; // $data['u'] = 1704251601802555535; $iapInfo = Db::name('iap_config')->where(['item_id'=>$data['i']])->find(); if(empty($iapInfo)) return (json(['error'=>1111])); $plugin = $this->payPluginModel->getPayPluginByType($data['t']); if(empty($plugin)) return (json(['error'=>1111])); $biz_content = $this->getAliTradeInfo($iapInfo, $data['u']); $val = $this->getAliPayInfo($plugin, $biz_content); return http_build_query($val); } public function notify(){ echo 'success'; } private function getAliTradeInfo($ipa, $user){ $content = []; $content['subject'] = $ipa['desc']; $content['out_trade_no'] = $tradeNo = 'D'.getId(); $content['total_amount'] = $ipa['price']; // $content['total_amount'] = 0.01; $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['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); $sign = aliSign($plugin['private_key'], getAliSignContent($params)); $params['sign'] = $sign; foreach ($params as &$value) { $value = urlencode($value); } return $params; } }