|
@@ -0,0 +1,94 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Libs\Pay\Merchants;
|
|
|
+
|
|
|
+use GuzzleHttp\Client;
|
|
|
+use Log;
|
|
|
+
|
|
|
+class OriginBank
|
|
|
+{
|
|
|
+ function __construct($config)
|
|
|
+ {
|
|
|
+ $this->open_id = $config['openId'];
|
|
|
+ $this->open_key = $config['openKey'];
|
|
|
+
|
|
|
+ $this->mchId = $config['mchId'];
|
|
|
+ $this->appkey = $config['appKey'];
|
|
|
+ $this->subAppid = $config['subAppid'];
|
|
|
+ $this->PayClient = new client(['base_uri'=>'https://mixpayuat4.orangebank.com.cn/','timeout'=>3]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成订单
|
|
|
+ function send($data)
|
|
|
+ {
|
|
|
+ $time = time();
|
|
|
+ $base_data = [
|
|
|
+ 'open_id'=>$this->open_id,
|
|
|
+ 'timestamp'=>$time,
|
|
|
+ ];
|
|
|
+ $data = [
|
|
|
+ 'out_no'=>$data['trade_no'],
|
|
|
+ 'pmt_tag'=>'Weixin',
|
|
|
+ 'ord_name'=>'小说充值',
|
|
|
+ 'original_amount'=>$data['price'],
|
|
|
+ 'trade_amount'=>$data['price'],
|
|
|
+ 'notify_url'=>env('ORIGINBANK_NOFITY_URL'),
|
|
|
+ 'sub_appid'=>$this->appId,
|
|
|
+ 'sub_openid'=>$data['openid']
|
|
|
+ ];
|
|
|
+
|
|
|
+ $base_data['data'] = $this->encrypt(json_encode($data),$this->open_key);
|
|
|
+
|
|
|
+ $base_data['sign'] = $this->signs($data);
|
|
|
+
|
|
|
+ dd($base_data);
|
|
|
+
|
|
|
+ $response = $this->PayClient->request('POST','mct1/payorder',$base_data)->getBody()->getContents();
|
|
|
+ dd($response);
|
|
|
+ return $this->getPayInfo($response);
|
|
|
+ }
|
|
|
+
|
|
|
+ function getPayInfo($response)
|
|
|
+ {
|
|
|
+ try{
|
|
|
+ $return_info = json_decode($response,1);
|
|
|
+ //dd($return_info);
|
|
|
+ if($return_info['errcode'] == 0)
|
|
|
+ {
|
|
|
+ return json_decode($return_info['result']['pay_info'],1);
|
|
|
+ }
|
|
|
+ }catch (\Exception $e)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //签名
|
|
|
+ public function signs($array){
|
|
|
+ $signature = array();
|
|
|
+ foreach($array as $key=>$value){
|
|
|
+ $signature[$key]=$key.'='.$value;
|
|
|
+ }
|
|
|
+ $signature['open_key']='open_key'.'='.$this->open_key;
|
|
|
+ ksort($signature);
|
|
|
+ #先sha1加密 在md5加密
|
|
|
+ $sign_str = md5(sha1(implode('&', $signature)));
|
|
|
+ return $sign_str;
|
|
|
+ }
|
|
|
+
|
|
|
+ #@todo AES加解密
|
|
|
+ #加密
|
|
|
+ public static function encrypt($input, $key) {
|
|
|
+ $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
|
|
|
+ $input = self::pkcs5_pad($input, $size);
|
|
|
+ $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
|
|
|
+ $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
|
|
+ mcrypt_generic_init($td, $key, $iv);
|
|
|
+ $data = mcrypt_generic($td, $input);
|
|
|
+ mcrypt_generic_deinit($td);
|
|
|
+ mcrypt_module_close($td);
|
|
|
+ $data = strtoupper(bin2hex($data));
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+}
|