{"id":30930270,"url":"https://github.com/peteryangs/wechat","last_synced_at":"2025-10-14T09:33:25.826Z","repository":{"id":57038195,"uuid":"388380757","full_name":"PeterYangs/wechat","owner":"PeterYangs","description":"wechat development sdk","archived":false,"fork":false,"pushed_at":"2021-07-29T14:59:52.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-10T12:29:15.900Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PeterYangs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-22T08:11:22.000Z","updated_at":"2021-07-29T14:59:55.000Z","dependencies_parsed_at":"2022-08-23T23:30:54.340Z","dependency_job_id":null,"html_url":"https://github.com/PeterYangs/wechat","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/PeterYangs/wechat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterYangs%2Fwechat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterYangs%2Fwechat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterYangs%2Fwechat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterYangs%2Fwechat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PeterYangs","download_url":"https://codeload.github.com/PeterYangs/wechat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeterYangs%2Fwechat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018631,"owners_count":26086404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-10T10:44:04.242Z","updated_at":"2025-10-14T09:33:25.810Z","avatar_url":"https://github.com/PeterYangs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 微信开发sdk\n\n### 安装\n```shell\ncomposer require peteryang/wechat\n```\n\n### 基本\n1.获取access_token\n```php\n\n#配置信息\n$config = new \\Config\\Config(\"appid\", \"appSecret\");\n\n$w = new \\WeChat\\WeChat($config);\n\necho $w-\u003egetAccessToken();\n```\n\n### 网页授权\n\n1.跳转页面获取code\n```php\n\u003c?php\n\nrequire \"../vendor/autoload.php\";\n\n#配置信息\n$config = new \\Config\\Config(\"appid\", \"appSecret\");\n\n$w = new \\WeChat\\WeChat($config);\n\n$url = $w-\u003eWebAuth()-\u003egetCodeRedirect(\"回调地址\");\n\nheader(\"location:\" . $url);\n```\n\n2.根据code获取用户信息\n```php\n\u003c?php\n\nrequire \"../vendor/autoload.php\";\n\n$w = new \\WeChat\\WeChat($config);\n\n$user_info = $w-\u003eWebAuth()-\u003egetUserInfoByCode($_GET['code']);\n\n\nprint_r($user_info);\n```\n\n### jsSdk\n1.获取jsapiTicket\n```php\n$w = new \\WeChat\\WeChat($config);\n\n$accessToken = $w-\u003egetAccessToken();\n\n\necho $w-\u003eJsSdk()-\u003egetTicket($accessToken);\n```\n\n2.wxConfig\n```php\n\u003c?php\n\n$w = new \\WeChat\\WeChat($config);\n\n$accessToken = $w-\u003egetAccessToken();\n\n$jsSdk = $w-\u003eJsSdk();\n\n$ticket = $jsSdk-\u003egetTicket($accessToken);\n\n$wxConfig = $jsSdk-\u003egetWxConfig($ticket, \"http://www.wechat.com/wxConfig.php\");\n?\u003e\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eTitle\u003c/title\u003e\n    \u003cscript src=\"jweixin-1.6.0.js\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cscript\u003e\n    wx.config({\n        debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。\n        appId: '\u003c?php echo $config-\u003egetAppId();?\u003e', // 必填，公众号的唯一标识\n        timestamp: \u003c?php echo $wxConfig-\u003egetTimestamp() ?\u003e, // 必填，生成签名的时间戳\n        nonceStr: '\u003c?php echo $wxConfig-\u003egetNonceStr() ?\u003e', // 必填，生成签名的随机串\n        signature: '\u003c?php echo $wxConfig-\u003egetSignature() ?\u003e',// 必填，签名\n        jsApiList: ['chooseImage'] // 必填，需要使用的JS接口列表\n    });\n\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\n\n```\n### 微信公众号支付\n调起支付\n```php\n\u003c?php\n\n\nuse Pay\\config\\PayConfig;\nuse Pay\\method\\js\\Js;\nuse Pay\\method\\js\\JsUnifiedOrder;\n\nrequire \"../vendor/autoload.php\";\n\n#测试号\n$config = new \\Config\\Config(\"appid\", \"appkey\");\n\n$w = new \\WeChat\\WeChat($config);\n\n#获取access_token\n$accessToken = $w-\u003egetAccessToken();\n\n$jsSdk = $w-\u003eJsSdk();\n\n#获取ticket\n$ticket = $jsSdk-\u003egetTicket($accessToken);\n\n#获取jssdk配置项\n$wxConfig = $jsSdk-\u003egetWxConfig($ticket, \"http://www.wechat.com/wxConfig.php\");\n\n\n#微信支付实例\n$pay = $w-\u003epay(new PayConfig(\"商户id\", \"商户秘钥\"));\n\n#选择支付方式\n$method = $pay-\u003echoose(new Js());\n\n#调用统一下单\n$payParameter = $method-\u003eunifiedorder(new JsUnifiedOrder(\n    \"商品描述\",\n    \"订单号\",\n    1,\n    \"ip\",\n    \"通知地址\",\n    \"openid\",\n    \"附加数据\"\n))-\u003egetPayParameter();\n\n\n?\u003e\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eTitle\u003c/title\u003e\n    \u003cscript src=\"jweixin-1.6.0.js\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cscript\u003e\n    wx.config({\n        debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。\n        appId: '\u003c?php echo $config-\u003egetAppId();?\u003e', // 必填，公众号的唯一标识\n        timestamp: \u003c?php echo $wxConfig-\u003egetTimestamp() ?\u003e, // 必填，生成签名的时间戳\n        nonceStr: '\u003c?php echo $wxConfig-\u003egetNonceStr() ?\u003e', // 必填，生成签名的随机串\n        signature: '\u003c?php echo $wxConfig-\u003egetSignature() ?\u003e',// 必填，签名\n        jsApiList: ['chooseImage'] // 必填，需要使用的JS接口列表\n    });\n\n\n    wx.ready(function () {\n        // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。\n        wx.chooseWXPay({\n            timestamp: \u003c?php echo $payParameter['timeStamp'];?\u003e, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符\n            nonceStr: '\u003c?php echo $payParameter['nonceStr'];?\u003e', // 支付签名随机串，不长于 32 位\n            package: '\u003c?php echo $payParameter['package'];?\u003e', // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\\*\\*\\*）\n            signType: '\u003c?php echo $payParameter['signType'];?\u003e', // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致\n            paySign: '\u003c?php echo $payParameter['paySign'];?\u003e', // 支付签名\n            success: function (res) {\n                // 支付成功后的回调函数\n\n\n            }\n        });\n\n\n    });\n\n\n\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n通知检查\n```php\n\u003c?php\n\nrequire \"../vendor/autoload.php\";\n\n\ntry {\n\n\n    #测试号\n    $config = new \\Config\\Config(\"appid\", \"appkey\");\n\n    $w = new \\WeChat\\WeChat($config);\n\n\n    $pay = $w-\u003epay(new \\Pay\\config\\PayConfig(\"xxxxx\", \"xxxx\"));\n\n    $method = $pay-\u003echoose(new \\Pay\\method\\js\\Js());\n\n    #验证失败会抛出异常，验证成功返回回调数据\n    $all=$method-\u003echeck()-\u003egetAll();\n    \n    //返回微信服务器成功消息\n    echo  \\Tool\\Tool::returnSuccess();\n\n} catch (\\Exception $exception) {\n\n\n    echo $exception-\u003egetMessage();\n\n}\n```\n### 微信小程序\n```php\n\u003c?php\nrequire \"../vendor/autoload.php\";\n\n#测试号\n$config = new \\Config\\Config(\"wx4f4bc4dec97d474b\", \"tiihtNczf5v6AKRyjwEUhQ==\");\n\n\n$w = new \\WeChat\\WeChat($config);\n\n#获取session和openid\n$app = $w-\u003eapp()-\u003egetSession($code);\n\n#解密\n$user = $w-\u003eapp()-\u003edecryptData('CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZM\n                QmRzooG2xrDcvSnxIMXFufNstNGTyaGS\n                9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+\n                3hVbJSRgv+4lGOETKUQz6OYStslQ142d\n                NCuabNPGBzlooOmB231qMM85d2/fV6Ch\n                evvXvQP8Hkue1poOFtnEtpyxVLW1zAo6\n                /1Xx1COxFvrc2d7UL/lmHInNlxuacJXw\n                u0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn\n                /Hz7saL8xz+W//FRAUid1OksQaQx4CMs\n                8LOddcQhULW4ucetDf96JcR3g0gfRK4P\n                C7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB\n                6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns\n                /8wR2SiRS7MNACwTyrGvt9ts8p12PKFd\n                lqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYV\n                oKlaRv85IfVunYzO0IKXsyl7JCUjCpoG\n                20f0a04COwfneQAGGwd5oa+T8yO5hzuy\n                Db/XcxxmK01EpqOyuxINew==', 'r7BXXKkLb8qrSNn05n0qiA==', 'tiihtNczf5v6AKRyjwEUhQ==');\n\n\n$info = $user-\u003egetAll();\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeteryangs%2Fwechat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeteryangs%2Fwechat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeteryangs%2Fwechat/lists"}