作者 景龙
1 个管道 的构建 失败 耗费 3 秒

调试企业付款

... ... @@ -35,7 +35,7 @@ class Line extends Backend
/**
* 查看
*/
public function index()
public function offline($ids)
{
//当前是否为关联查询
$this->relationSearch = true;
... ... @@ -49,11 +49,10 @@ class Line extends Backend
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$uid = $this->request->param('ids');
$total = $this->model
->with(['user'])
->where($where)
->where('uid',$uid)
->where('uid',$ids)
->group('off_uid')
->order($sort, $order)
->count();
... ... @@ -62,7 +61,7 @@ class Line extends Backend
->with(['user'])
->field('sum(s_score) as score')
->where($where)
->where('uid',$uid)
->where('uid',$ids)
->group('off_uid')
->order($sort, $order)
->limit($offset, $limit)
... ... @@ -77,6 +76,7 @@ class Line extends Backend
return json($result);
}
$this->assignconfig("uid",$ids);
return $this->view->fetch();
}
}
... ...
不能预览此文件类型
-----BEGIN CERTIFICATE-----
MIIEczCCA9ygAwIBAgIEAjpYmTANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMC
Q04xEjAQBgNVBAgTCUd1YW5nZG9uZzERMA8GA1UEBxMIU2hlbnpoZW4xEDAOBgNV
BAoTB1RlbmNlbnQxDDAKBgNVBAsTA1dYRzETMBEGA1UEAxMKTW1wYXltY2hDQTEf
MB0GCSqGSIb3DQEJARYQbW1wYXltY2hAdGVuY2VudDAeFw0xODA5MjMwODU5MDda
Fw0yODA5MjAwODU5MDdaMIGiMQswCQYDVQQGEwJDTjESMBAGA1UECBMJR3Vhbmdk
b25nMREwDwYDVQQHEwhTaGVuemhlbjEQMA4GA1UEChMHVGVuY2VudDEOMAwGA1UE
CxMFTU1QYXkxNjA0BgNVBAMULeW5v+ilv+Wwj+e6uOearuWGjeeUn+i1hOa6kOWb
nuaUtuaciemZkOWFrOWPuDESMBAGA1UEBBMJMTAyNDc0NTU3MIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtCiZ9NGAYBPhCIO0I1aHTNCEYCpi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XL+sLJREZ1btKCOZd2YMcHDpgZMK9c2djVIeOoOd3p
S1Yw0dryM76A1h4iW3k5o4ONuefVx2o9XEFUbRjaxVDMbSP2KP4ZpT3Pp0wtRCGR
ZN4EzcOiFKF1vjSEOZSlHDMgSflV20wxoQ3dlq2PEt/vfzUoSeQ0OmuNAoGBAIt3
T4dRajjLs5c0FeUk6JBB7zSMWUCDDs/Rf8FToaBig1KWXjhTfextrfuboLH4dmrt
r4JvRn/mN4Z0KvLspfs8SsIHsOHhQFTVBoJu6y9P7yhB2UBalRXlDqEzwmqIHYOO
fCo12XO4I476WHwAJ/Ay9IzoEC1/rU37F/FzRsQdAoGADH4rQb/rSo9ZjZxb5fu2
z1I6jEw7vFMtWToZsOdF3nnVhNn5a5Lojj7HzCoeKSCTW9wsCoCBIUwVnStRZpqE
BdtwWs53uq1ERThKXmkVEgUgD8FL8PT/khSL8N44KeuB3MJ5uL4fKhRQDV3LeqxC
Cd58ve4U1mn+QVokNnguEM0=
-----END PRIVATE KEY-----
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
use addons\epay\library\Service;
use app\admin\model\Porder;
use think\Db;
use Yansongda\Pay\Pay;
use app\admin\model\Account;
use app\admin\model\User;
use app\admin\model\Message;
use app\admin\model\Car;
use app\admin\model\Product;
use think\Log;
use fast\Http;
use think\Validate;
use Exception;
/**
* 企业付款接口**
*/
class Paybank extends Api
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $user_id = '';//token存贮user_id
protected $KEY = 'cccccccccccccccccccccccccccccc00'; //商户秘钥
private $params;
public function _initialize()
{
parent::_initialize();
$this->user_id = $this->auth->getUserId();
}
//获取公钥
public function getPuyKey(){
$this->params = [
'mch_id' => '1515355581',//商户ID
'nonce_str' => md5(time()),
'sign_type' => 'MD5',
];
//将数据发送到接口地址
$res = $this->send("https://fraud.mch.weixin.qq.com/risk/getpublickey");
var_dump($res);exit;
}
// public function payBank(){
// if($this->request->isPost()){
// $rsa = new Rsa(file_get_contents(url('/addons/epay/certs/apiclient_cert.pem','','',true)), '');
// $data = [
// 'enc_bank_no' => $rsa->public_encrypt('1234342343234234'),//收款方银行卡号RSA加密
// 'enc_true_name' => $rsa->public_encrypt('李明'),//收款方姓名RSA加密
// 'bank_code' => '1002',//收款方开户行
// 'amount' => '1',//付款金额
// ];
// $res = $this->bankPay($data);
// var_dump($res);exit;
// }else{
// $this->error('请求方式错误');
// }
// }
//
// private function bankPay($data){
// //构建原始数据
// $this->params = [
// 'mch_id' => '1515355581',//商户号
// 'partner_trade_no' => $this->auth->genPayOrderSn(),//商户付款单号
// 'nonce_str' => md5(time()), //随机串
// 'enc_bank_no' => $data['enc_bank_no'],//收款方银行卡号RSA加密
// 'enc_true_name' => $data['enc_true_name'],//收款方姓名RSA加密
// 'bank_code' => $data['bank_code'],//收款方开户行
// 'amount' => $data['amount'],//付款金额
// ];
// //将数据发送到接口地址
// return $this->send('https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank');
// }
public function send($url){
$res = $this->sign();
$xml = $this->ArrToXml($res);
$returnData = $this->postData($url, $xml);
var_dump($returnData);exit;
return $this->XmlToArr($returnData);
}
public function sign(){
return $this->setSign($this->params);
}
//数组转xml
public function ArrToXml($arr)
{
if(!is_array($arr) || count($arr) == 0) return '';
$xml = "<xml>";
foreach ($arr as $key=>$val)
{
if (is_numeric($val)){
$xml.="<".$key.">".$val."</".$key.">";
}else{
$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
}
}
$xml.="</xml>";
return $xml;
}
/**
* 获取签名
* @param array $arr
* @return string
*/
public function getSign($arr){
//去除空值
$arr = array_filter($arr);
if(isset($arr['sign'])){
unset($arr['sign']);
}
//按照键名字典排序
ksort($arr);
//生成url格式的字符串
$str = $this->arrToUrl($arr) . '&key=' .$this->KEY;
return strtoupper(md5($str));
}
/**
* 获取带签名的数组
* @param array $arr
* @return array
*/
public function setSign($arr){
$arr['sign'] = $this->getSign($arr);
return $arr;
}
/**
* 数组转URL格式的字符串
* @param array $arr
* @return string
*/
public function arrToUrl($arr){
return urldecode(http_build_query($arr));
}
//Xml转数组
public function XmlToArr($xml){
if($xml == '') return '';
libxml_disable_entity_loader(true);
$arr = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $arr;
}
//发送数据
public function postData($url,$postfields){
$ch = curl_init();
$params[CURLOPT_URL] = $url; //请求url地址
$params[CURLOPT_HEADER] = false; //是否返回响应头信息
$params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
$params[CURLOPT_FOLLOWLOCATION] = true; //是否重定向
$params[CURLOPT_POST] = true;
$params[CURLOPT_POSTFIELDS] = $postfields;
$params[CURLOPT_SSL_VERIFYPEER] = false;
$params[CURLOPT_SSL_VERIFYHOST] = false;
//以下是证书相关代码
$params[CURLOPT_SSLCERTTYPE] = 'PEM';
$params[CURLOPT_SSLCERT] = '../certs/apiclient_cert.pem';
$params[CURLOPT_SSLKEYTYPE] = 'PEM';
$params[CURLOPT_SSLKEY] = '../certs/apiclient_key.pem';
curl_setopt_array($ch, $params); //传入curl参数
$content = curl_exec($ch); //执行
curl_close($ch); //关闭连接
return $content;
}
}
... ...
<?php
namespace app\api\controller;
class RSA{
private $public_key_resource = ''; //公钥资源
private $private_key_resource = ''; //私钥资源
/**
* 构造函数
* @param [string] $public_key [公钥数据字符串]
* @param [string] $private_key [私钥数据字符串]
*/
public function __construct($public_key,$private_key) {
$this->public_key_resource = !empty($public_key) ? openssl_pkey_get_public($this->get_public_key($public_key)) : false;
$this->private_key_resource = !empty($private_key) ? openssl_pkey_get_private($this->get_private_key($private_key)) : false;
}
/**
获取私有key字符串 重新格式化 为保证任何key都可以识别
*/
public function get_private_key($private_key){
$search = [
"-----BEGIN RSA PRIVATE KEY-----",
"-----END RSA PRIVATE KEY-----",
"\n",
"\r",
"\r\n"
];
$private_key=str_replace($search,"",$private_key);
return $search[0] . PHP_EOL . wordwrap($private_key, 64, "\n", true) . PHP_EOL . $search[1];
}
/**
获取公共key字符串 重新格式化 为保证任何key都可以识别
*/
public function get_public_key($public_key){
$search = [
"-----BEGIN PUBLIC KEY-----",
"-----END PUBLIC KEY-----",
"\n",
"\r",
"\r\n"
];
$public_key=str_replace($search,"",$public_key);
return $search[0] . PHP_EOL . wordwrap($public_key, 64, "\n", true) . PHP_EOL . $search[1];
}
/**
* 生成一对公私钥 成功返回 公私钥数组 失败 返回 false
*/
public function create_key() {
$res = openssl_pkey_new();
if($res == false) return false;
openssl_pkey_export($res, $private_key);
$public_key = openssl_pkey_get_details($res);
return array('public_key'=>$public_key["key"],'private_key'=>$private_key);
}
/**
* 用私钥加密
*/
public function private_encrypt($input) {
openssl_private_encrypt($input,$output,$this->private_key_resource);
return base64_encode($output);
}
/**
* 解密 私钥加密后的密文
*/
public function public_decrypt($input) {
openssl_public_decrypt(base64_decode($input),$output,$this->public_key_resource);
return $output;
}
/**
* 用公钥加密
*/
public function public_encrypt($input) {
openssl_public_encrypt($input,$output,$this->public_key_resource,OPENSSL_PKCS1_OAEP_PADDING);
return base64_encode($output);
}
/**
* 解密 公钥加密后的密文
*/
public function private_decrypt($input) {
openssl_private_decrypt(base64_decode($input),$output,$this->private_key_resource,OPENSSL_PKCS1_OAEP_PADDING);
return $output;
}
}
... ...
... ... @@ -75,11 +75,10 @@ class Wxpay extends Api
$order = [
'out_trade_no' => $pay_order_sn,//支付订单号
'body' => '广西小纸皮再生资源回收有限公司',
// 'total_fee' => 1,
'total_fee' => floatval($total_price)*100,//单位:分
'total_fee' => 1,
// 'total_fee' => floatval($total_price)*100,//单位:分
'openid' => $openid,
'notify_url' => url('api/Wxpay/notify','','',true),
'return_url' => url('api/Wxpay/notify','','',true),
];
//跳转或输出
$this->success('成功',$pay->miniapp($order));
... ... @@ -137,7 +136,7 @@ class Wxpay extends Api
$porderModel = new Porder();
$porderModel->where(['pay_order_sn'=>$data['out_trade_no']])->update(['status'=>$this->order_status[1]]);
//减库存,删相应购物车记录
$this->handle($data['out_trade_no']);
$this->handle($data['out_trade_no'],$data['openid']);
}
} catch (Exception $e) {
echo "验签失败";
... ... @@ -204,7 +203,7 @@ class Wxpay extends Api
//充值记录
$accountModel = new Account();
$account = $accountModel::create(['uid' => $user['id'], 'money' => $money]);
$account = $accountModel::create(['uid' => $user['id'], 'money' => $money,'partner_trade_no'=>$data['out_trade_no']]);
//系统充值消息
$messageModel = new Message();
... ... @@ -249,8 +248,12 @@ class Wxpay extends Api
}
}
public function handle($pay_order_sn){
/**
* 支付完成处理库存,购物车
* @param $pay_order_sn
* @param $openid
*/
public function handle($pay_order_sn,$openid){
//查询订单信息的商品id,数量num
$data = Db::table('gc_porder')
->where(['pay_order_sn'=>$pay_order_sn])
... ... @@ -264,7 +267,7 @@ class Wxpay extends Api
->select();
foreach($product as &$p_value){
foreach($data as $value){
if($p_value['id'] == $value['p_id']){
if($value['p_id'] == $p_value['id']){
$p_value['stock'] = $p_value['stock'] - $value['num'];
}
}
... ... @@ -274,11 +277,10 @@ class Wxpay extends Api
$productModel->saveAll($product);
$userModel = new User();
$user = $userModel->where(['openid' => $data['openid']])->find();
$user = $userModel->where(['openid' => $openid])->find();
//清理购物车
$carModel = new Car();
$carModel->whereIn('p_id',$pIds)->where('uid',$user['id'])->delete();
}
}
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
offline: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'off/line/index',
index_url: 'off/line/offline',
// add_url: 'off/line/add',
// edit_url: 'off/line/edit',
// del_url: 'off/line/del',
// multi_url: 'off/line/multi',
table: 'off_line',
},
queryParams: function (params) { //自定义搜索条件
params.ids = Config.uid;//将搜索过滤器和操作方法 都转为JSON字符串
return params;
}
});
... ...
... ... @@ -44,7 +44,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons: [
{name: 'log', text: '我的团队', title: '我的团队', icon: 'fa fa-list', classname: 'btn btn-xs btn-success btn-dialog', url: "off/line/index"}
{name: 'offline', text: '我的团队', title: '我的团队', icon: 'fa fa-list', classname: 'btn btn-xs btn-success btn-dialog', url: "off/line/offline"}
]}
]
]
... ...