NET C#实现微信小微商户进件API,微信小微商户申请

官方小微商户专属接口文档
微信小微商户都是你的应用程序.NET C#

申请状态查询返回数据

微信支付SDK

微信支付官方SDK与DEMO下载

图片上传

图片上传接口API文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Helper.Http;
using Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using WxPayAPI;
 
namespace WechatXiaowei.upmedia
{
    class upimage
    {
        /// <summary>
        /// 上传本地图片到微信服务器
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static result localfile(string filePath)
        {
            FileStream file = new FileStream(filePath, FileMode.Open);
            byte[] bb = new byte[file.Length];
            file.Read(bb, 0, (int)file.Length);
            file.Close();
            string fileName = Path.GetFileName(filePath);
            MsMultiPartFormData form = new MsMultiPartFormData();
            string decodeName = HttpUtility.UrlDecode(Path.GetFileName(fileName));//最终服务器会按原文件名保存文件,所以需要将文件名编码下,防止中文乱码
            string fileKeyName = "media";
            form.AddStreamFile(fileKeyName, fileName, bb);
 
             
            string hashMd5 =HashHelper.ComputeMD5(filePath);
 
            WxPayData inputObj = new WxPayData();
            inputObj.SetValue("mch_id", Config.GetMchID);
            inputObj.SetValue("media_hash", hashMd5);
            inputObj.SetValue("sign_type", "HMAC-SHA256");
            //inputObj.SetValue("sign", inputObj.MakeSign());//签名
 
            form.AddFormField("mch_id", Config.GetMchID);
            form.AddFormField("media_hash", hashMd5);
            form.AddFormField("sign_type", "HMAC-SHA256");
            form.AddFormField("sign", inputObj.MakeSign());//签名
 
            //最终接收文件上传的服务接口
            string SERVICE_URL = "https://api.mch.weixin.qq.com/secapi/mch/uploadmedia";
 
            string rst = Http.PostWithMsMultiPartFormData(inputObj.ToXml(), SERVICE_URL, form, true, 10);
 
            inputObj = new WxPayData();
            inputObj.FromXml(rst);
 
            //返回实体结果
            result result = null;
            if (inputObj.GetValue("return_code").ToString() == "SUCCESS")
            {
                result = new Model.upimage.result()
                {
                    code = Result.SUCCESS,
                    media_id = inputObj.GetValue("media_id").ToString()
                };
            }
            else
            {
                result = new Model.upimage.result()
                {
                    code = Result.FAIL,
                    message = inputObj.GetValue("return_msg").ToString()
                };
            }
            return result;
        }
 
    }
}

关键:multipart/form-data 格式上传图片 + 签名
参考:https://blog.csdn.net/pjj802366/article/details/51645150

证书下载
证书下载接口API文档

关键1:Authorization加密信息生成
关键2:证书解密《通过以下PHP解决》

敏感信息加密(+证书解密)
敏感信息加密API说明

参考:https://blog.csdn.net/u010324331/article/details/81938979
注意:这个功能是通过PHP方式解决加密的问题
使用>Php7.2,开启下libsodium扩展。方法为:在php.ini 增加: extension=php_sodium.dll

$ciphertext = base64_decode($_POST['ciphertext']);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ciphertext = base64_decode($_POST['ciphertext']);
$associated_data= $_POST['associated_data'];
$nonce  = $_POST['nonce'];
$aes_key= '自己设定key';
 
 
// sodium_crypto_aead_aes256gcm_decrypt >=7.2版本,去php.ini里面开启下libsodium扩展就可以,之前版本需要安装libsodium扩展,
//具体查看php.net(ps.使用这个函数对扩展的版本也有要求哦,扩展版本 >=1.08)
//$b= sodium_crypto_aead_aes256gcm_is_available();
 
$plaintext  = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associated_data, $nonce, $aes_key);
//print_r( $plaintext,false );
 
//敏感信息加密
$string = $_POST['string'];
$publicKeyResource = openssl_get_publickey($plaintext);
$f= openssl_public_encrypt($string, $crypted, $publicKeyResource, OPENSSL_PKCS1_PADDING);
openssl_free_key($publicKeyResource);
if ($f) {
    print_r( base64_encode($crypted));
}
?>

  

身份证识别

腾讯云身份证识别API文档,免费次数:1000次/月
待续20180922

.库源码已放到到GitHub

日期: 2019 02 01不依赖PHP 独立完成加密处理
https://github.com/onsuper/XiaoWei

 

posted @   多见多闻  阅读(176)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示