tp接入富友H5支付

富友H5支付集成指南
本文档介绍了如何在应用程序中接入富友的H5支付,包括控制器中的关键方法设置及异步回调处理流程。

控制器里方法:

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;

}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值