• 微信支付(APP)


    折腾了一天,终于搞定了微信支付,总结一下。首先从服务器端获取prepareid,Andorid 端再根据这个prepareid二次签名。

    服务器端:

    从官网上下载DEMO,Demo中只有JsAPi,Micro,Native。没有APP的,那怎么办呢?模仿着jsAPi的自己写一个。

    第一步:配置WxPay.Config.php

    const APPID = 'wx004d72dd9aab9cc5';
    const MCHID = '1293496801';
    const KEY = 'zcvnoasdfasnvu93n320dvndsf98nlds';
    
    

    第二步:替换cert

    const SSLCERT_PATH = '../cert/apiclient_cert.pem';
    const SSLKEY_PATH = '../cert/apiclient_key.pem';
    

    第三步:统一下单

    <?php 
    ini_set('date.timezone','Asia/Shanghai');
    require_once "../lib/WxPay.Api.php";
    
    //①、获取用户openid
    //$tools = new JsApiPay();
    //$openId = $tools->GetOpenid();
    
    //②、统一下单
    $input = new WxPayUnifiedOrder();
    $input->SetBody("test");
    $input->SetAttach("test");
    $input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
    $input->SetTotal_fee("1");
    $input->SetTime_start(date("YmdHis"));
    $input->SetTime_expire(date("YmdHis", time() + 600));
    $input->SetGoods_tag("test");
    $input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
    $input->SetTrade_type("APP");
    //$input->SetOpenid($openId);
    $order = WxPayApi::unifiedOrder($input);
    
    $parameters = json_encode($order);
    echo $parameters;
    

    Android端

    private void weixinPay() {
    
            final IWXAPI msgApi = WXAPIFactory.createWXAPI(getActivity(), null);
            msgApi.registerApp(Constants.APP_ID);
            String url = "http://192.168.208.34/WxpayAPI/example/appapi.php";
    
            Toast.makeText(getActivity(), "获取订单中...", Toast.LENGTH_SHORT).show();
    
            HttpUtil.sendJsonRequest(HttpRequest.HttpMethod.GET, url, null, new HttpRequestCallBack<Object>() {
                @Override
                public void onSuccessed(ResponseInfo<Object> responseInfo) {
                    Log.e("Josen", responseInfo.result.toString());
                    prePayBean = new Gson().fromJson(responseInfo.result.toString(), PrePayBean.class);
                    PayReq req = new PayReq();
                    req.appId = prePayBean.getAppid();
                    req.partnerId = prePayBean.getMch_id();
                    req.prepayId = prePayBean.getPrepay_id();
                    req.nonceStr = RandomString.getRandomString(20);
                    req.timeStamp = String.valueOf(System.currentTimeMillis()/1000);
                    req.packageValue = "Sign=WXPay";
    
                    String string = "appid="+Constants.APP_ID+"&noncestr="
                            +req.nonceStr+"&package="+req.packageValue+"&partnerid="
                            +req.partnerId+"&prepayid="+req.prepayId+"&timestamp="
                            +req.timeStamp+"&key="+Constants.APP_KEY;
    
    
                    String sign = MD5.getMessageDigest(string.getBytes());
                    req.sign = sign.toUpperCase();
                    msgApi.sendReq(req);
    
                }
    
                @Override
                public void onFailed(HttpException exception, String reason) {
    
                }
            }, 0);
    
        }
    

      

  • 相关阅读:
    常用Linux命令
    SQL必知必会-笔记
    【ubuntu】install openbox+tint2+bmenu on ubuntu12.04.4
    【ruby】安装Ruby
    【ruby】快速安装gems的方法
    【sinatra】设置默认的端口
    【sinatra】修改默认ip绑定
    【sinatra】结合Padrino framework
    【sinatra】安装测试
    【rails3教材】博客构建过程2
  • 原文地址:https://www.cnblogs.com/qiaoshouliang/p/5102832.html
Copyright © 2020-2023  润新知