控制器里方法:
public function __construct()
{
$this->config = config('pay');
$this->client = new \GuzzleHttp\Client();
parent::__construct();
}
public function payAction(){
$name = input('name');
$id_num = input('id_num');
$fee = input('fee');
$card_num = input('card_num');
$success_url = input('success_url');
$fail_url = input('fail_url');
$userid=input('uid');
if (!($name&&$id_num&&$fee&&$card_num&&$success_url&&$fail_url&&$userid)) {
return json(['code'=>208,'msg'=>'参数缺失']);
}
$postFm='https://mpay.fuioupay.com:16128/h5pay/payAction.pay';
$type='10';
$version="2.0";
$mchntcd='0003320F2144992';
$mchntorderid=date('YmdHis',time()).mt_rand(1000,9999);
$amt=$fee;
$bankcard=$card_num;
$backurl="http://自己项目域名/api/Pay/h5Notify";
$idno=$id_num;
$idtype=0;
$logotp=0;
$homeurl=$success_url;
$reurl=$fail_url;
$key="zxppac23oeolb9gweugjxt1d8ktxpgkh";
$rem1="";
$rem2="";
$rem3="";
$signtp="md5";
$sign = $type."|".$version."|".$mchntcd."|".$mchntorderid ."|".$userid."|".$amt."|".$bankcard."|".$backurl."|".
$name."|".$idno."|".$idtype."|".$logotp."|".$homeurl."|".$reurl."|".$key;
$fm = "<ORDER>"
."<VERSION>".$version."</VERSION>"
."<LOGOTP>".$logotp."</LOGOTP>"
."<MCHNTCD>".$mchntcd."</MCHNTCD> "
."<TYPE>".$type."</TYPE>"
."<MCHNTORDERID>".$mchntorderid."</MCHNTORDERID>"
."<USERID>".$userid."</USERID>"
."<AMT>".$amt."</AMT>"
."<BANKCARD>".$bankcard."</BANKCARD>"
."<NAME>".$name."</NAME>"
."<IDTYPE>".$idtype."</IDTYPE>"
."<IDNO>".$idno."</IDNO>"
."<BACKURL>".$backurl."</BACKURL>"
."<HOMEURL>".$homeurl."</HOMEURL>"
."<REURL>".$reurl."</REURL>"
."<REM1>".$rem1."</REM1>"
."<REM2>".$rem2."</REM2>"
."<REM3>".$rem3."</REM3>"
."<SIGNTP>".$signtp."</SIGNTP>"
."<SIGN>".md5($sign)."</SIGN>"
."</ORDER>";
$data = [
'userid' => $userid,
'version' => "2.0",
'type' => "10",
'mchntorderid' => $mchntorderid,
'bankcard' => $card_num,
'amt' => $fee,
'created_at' => time()
];
Db::table('repayment')->insert($data);
$resFm = $this->getResult($postFm,$fm,true);
var_dump($resFm);
}
/**
* des加密,ecb
* @param $str
* @param $key
* @return string
*/
public static function encrypt_base64($str,$key){
$str = self::pkcs5_pad($str, 8);
if (strlen($str) % 8) {
$str = str_pad($str,strlen($str) + 8 - strlen($str) % 8, "\0");
}
$sign = openssl_encrypt($str,'DES-ECB' ,$key,OPENSSL_RAW_DATA);
return base64_encode($sign);
}
/**
* des解密
* @param $str
* @param $key
* @return string
*/
public static function decrypt_base64($str,$key){
$sign = openssl_decrypt(base64_decode($str),'DES-ECB' ,$key,OPENSSL_RAW_DATA);
return $sign;
}
/**
* 数据填充
* @param $text
* @param $blocksize
* @return string
*/
private static function pkcs5_pad($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
private function getResult($postUrl,$apifms,$fm = false)
{
$secret = 'zxppac23oeolb9gweugjxt1d8ntxpgkh';
$apifms = self::encrypt_base64($apifms,$secret);
$url = $postUrl.'?MCHNTCD=0003320F2144992&VERSION=2.0&ENCTP=1&FM='.$apifms;
$this->success('success',['url'=>$url],200);
}
另一个控制器里异步回调方法:
/**
* h5支付回调
*/
public function h5Notify(){
$status = 0;
if(input('RESPONSECODE')=='0000'){
$status = 1;
}
$data = [
'version' => input('VERSION'),
'type' => input('TYPE'),
'orderid' => input('ORDERID'),
'bankcard' => input('BANKCARD'),
'amt' => input('AMT'),
'responsemsg' => input('RESPONSEMSG'),
'status' =>$status
];
Repayment::where('mchntorderid',input('MCHNTORDERID'))->update($data);
return;
}
富友H5支付集成指南
本文档介绍了如何在应用程序中接入富友的H5支付,包括控制器中的关键方法设置及异步回调处理流程。
768

被折叠的 条评论
为什么被折叠?



