weixin | Auxiliary collection of WeChat mini | Runtime Evironment library

 by   game-helper JavaScript Version: 1.4.0 License: GPL-3.0

kandi X-RAY | weixin Summary

weixin is a JavaScript library typically used in Server, Runtime Evironment, Nodejs, MongoDB applications. weixin has no bugs, it has no vulnerabilities, it has a Strong Copyleft License and it has medium support. You can download it from GitHub.
Auxiliary collection of WeChat mini-games (addition and subtraction master, including you understand me, let's find the difference Tencent version, brain king, friends draw me, joyful notes, I am the best, star WeGoing, guessing small songs, Zhihu answering king, Tencent Chinese Chess, Tiao Yi
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        weixin has a medium active ecosystem.
                        summary
                        It has 1299 star(s) with 389 fork(s). There are 72 watchers for this library.
                        summary
                        It had no major release in the last 12 months.
                        summary
                        There are 24 open issues and 23 have been closed. On average issues are closed in 213 days. There are no pull requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of weixin is 1.4.0
                        weixin Support
                          Best in #Runtime Evironment
                            Average in #Runtime Evironment
                            weixin Support
                              Best in #Runtime Evironment
                                Average in #Runtime Evironment

                                  kandi-Quality Quality

                                    summary
                                    weixin has 0 bugs and 15 code smells.
                                    weixin Quality
                                      Best in #Runtime Evironment
                                        Average in #Runtime Evironment
                                        weixin Quality
                                          Best in #Runtime Evironment
                                            Average in #Runtime Evironment

                                              kandi-Security Security

                                                summary
                                                weixin has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                weixin code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                weixin Security
                                                  Best in #Runtime Evironment
                                                    Average in #Runtime Evironment
                                                    weixin Security
                                                      Best in #Runtime Evironment
                                                        Average in #Runtime Evironment

                                                          kandi-License License

                                                            summary
                                                            weixin is licensed under the GPL-3.0 License. This license is Strong Copyleft.
                                                            summary
                                                            Strong Copyleft licenses enforce sharing, and you can use them when creating open source projects.
                                                            weixin License
                                                              Best in #Runtime Evironment
                                                                Average in #Runtime Evironment
                                                                weixin License
                                                                  Best in #Runtime Evironment
                                                                    Average in #Runtime Evironment

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        weixin releases are available to install and integrate.
                                                                        summary
                                                                        Installation instructions are not available. Examples and code snippets are available.
                                                                        summary
                                                                        weixin saves you 107 person hours of effort in developing the same functionality from scratch.
                                                                        summary
                                                                        It has 272 lines of code, 24 functions and 137 files.
                                                                        summary
                                                                        It has low code complexity. Code complexity directly impacts maintainability of the code.
                                                                        weixin Reuse
                                                                          Best in #Runtime Evironment
                                                                            Average in #Runtime Evironment
                                                                            weixin Reuse
                                                                              Best in #Runtime Evironment
                                                                                Average in #Runtime Evironment
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed weixin and discovered the below as its top functions. This is intended to give you an instant insight into weixin implemented functionality, and help decide if they suit your requirements.
                                                                                  • define module export
                                                                                    • wrap the return function so that we can return a promise
                                                                                      • Send a reply .
                                                                                        • simple comparison function
                                                                                          • Common builder .
                                                                                            • Get a bit number .
                                                                                              • returns an array of indices
                                                                                                • Define a function
                                                                                                  Get all kandi verified functions for this library.
                                                                                                  Get all kandi verified functions for this library.

                                                                                                  weixin Key Features

                                                                                                  Auxiliary collection of WeChat mini-games (addition and subtraction master, including you understand me, let's find the difference Tencent version, brain king, friends draw me, joyful notes, I am the best, star WeGoing, guessing small songs, Zhihu answering king, Tencent Chinese Chess, Tiao Yi Tiao, Duoduo Gold Edition)

                                                                                                  weixin Examples and Code Snippets

                                                                                                  No Code Snippets are available at this moment for weixin.
                                                                                                  Community Discussions

                                                                                                  Trending Discussions on weixin

                                                                                                  Why I need extra `-k` flag when I curl over ip rather than hostname?
                                                                                                  chevron right
                                                                                                  Debug WeChat OAuth2 in localhost testing environment
                                                                                                  chevron right
                                                                                                  Where is the submit button in a WeChat Official Account app?
                                                                                                  chevron right
                                                                                                  Add random Font Awesome icons to html
                                                                                                  chevron right
                                                                                                  how to use selenium to take full screenshot with lots of dynamic loading images?
                                                                                                  chevron right
                                                                                                  Wechat H5 payment does not work
                                                                                                  chevron right
                                                                                                  WeChat Social Login
                                                                                                  chevron right
                                                                                                  NativeScript navigate to another page from custom Android activity
                                                                                                  chevron right
                                                                                                  Wechat - unable to send rich media messages more than 1
                                                                                                  chevron right
                                                                                                  c# URL POST Web API
                                                                                                  chevron right

                                                                                                  QUESTION

                                                                                                  Why I need extra `-k` flag when I curl over ip rather than hostname?
                                                                                                  Asked 2020-Oct-26 at 08:56

                                                                                                  I have this code

                                                                                                  $ curl  "https://api.weixin.qq.com:443/sns/jscode2session?appid=a&secret=b&js_code=c&grant_type=authorization_code"
                                                                                                  

                                                                                                  and it can get response from server like the following

                                                                                                  {"errcode":40013,"errmsg":"invalid appid rid: 5f96703e-5e24e4f1-691a9221"}
                                                                                                  

                                                                                                  However when I try to replace hostname into ip, I failed with the following message

                                                                                                  $ host api.weixin.qq.com
                                                                                                  api.weixin.qq.com has address 180.97.7.108
                                                                                                  api.weixin.qq.com has address 101.226.212.27
                                                                                                  
                                                                                                  $ curl  "https://101.226.212.27:443/sns/jscode2session?appid=a&secret=b&js_code=c&grant_type=authorization_code"
                                                                                                  curl: (60) SSL: no alternative certificate subject name matches target host name '101.226.212.27'
                                                                                                  More details here: https://curl.haxx.se/docs/sslcerts.html
                                                                                                  
                                                                                                  curl failed to verify the legitimacy of the server and therefore could not
                                                                                                  establish a secure connection to it. To learn more about this situation and
                                                                                                  how to fix it, please visit the web page mentioned above.
                                                                                                  

                                                                                                  I hanve to add -k to make this work

                                                                                                  $ curl  "https://101.226.212.27:443/sns/jscode2session?appid=a&secret=b&js_code=c&grant_type=authorization_code" -k
                                                                                                  {"errcode":40013,"errmsg":"invalid appid rid: 5f967132-1ee77e4b-2f378192"}c
                                                                                                  

                                                                                                  I want to know why this happen, and if there is any secure problems here? If there is any, how can I remove this -k flag?

                                                                                                  ANSWER

                                                                                                  Answered 2020-Oct-26 at 08:56

                                                                                                  Without -k (or the long version --insecure), curl makes sure that the host you connect to (specified in the URL) is also correctly mentioned in the certificate provided by the server when it connects to it, as part of the TLS handshake. The check is done to make sure that it speaks to the legitimate machine.

                                                                                                  The server certificate contains a list of host names (or wildcards) that curl checks if they match the host name in the URL.

                                                                                                  When you specify an IP address in the URL, curl can only use that to compare against the names in the certificate. A server can still list specific IP addresses (https://1.1.1.1 is for example known to) but is very rare and rather exceptional.

                                                                                                  The better fix

                                                                                                  Instead of using the IP address in the command line, use --resolve to use the right host name and make sure curl connects to the exact IP address of your choice.

                                                                                                  Warning

                                                                                                  Using -k completely disables curl's certificate check and you may then be subject for a MITM attack without being able to detect that.

                                                                                                  Source https://stackoverflow.com/questions/64532570

                                                                                                  QUESTION

                                                                                                  Debug WeChat OAuth2 in localhost testing environment
                                                                                                  Asked 2020-Sep-24 at 03:04

                                                                                                  I would like to implement a web application for a company in China. I need to use WeChat mini-APP to make the sign-up/login straight-forward.

                                                                                                  Please correct my assumptions if I am wrong:

                                                                                                  • To implement the login of the website from WeChat, I need to use the OAuth2 protocol
                                                                                                  • I also need to create a WeChat developer account under a real name (need ID card or business registration stuff) if I want to diffuse the application
                                                                                                  • I also need to register a domain name to WeChat so that they can allow OAuth2 authentication to this domain name

                                                                                                  Question: can I still use my localhost virtual machine to develop my server? (I didn't try but I assume WeChat will reject to create an OAuth2 token for localhost 127.0.0.1)

                                                                                                  Or do I need to have a development domain name with a development server available from the Internet so that I can debug the OAuth2 authentication?

                                                                                                  EDIT 1: I tried to send a HTTPS POST request https://127.0.0.1:8080 and I got an error linking to this URL https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html

                                                                                                  EDIT 2: I tried to send a HTTPS POST request https://192.168.1.148:8080 which correspond to my dev computer and I got the error VM17415:1 Cannot send network request to localhost. (My test phone and computer both connected to network 192.168.1.x trough WiFi)

                                                                                                  ANSWER

                                                                                                  Answered 2020-Sep-24 at 03:04

                                                                                                  The documentation is available in English on the official WebSite [1]. It is written: network APIs allow communication with LAN IP addresses. So basically, if the phone is connected to the same network as the virtual machine (i.e. WiFi), one should be able to send any kind of HTTP/HTTPS request properly.

                                                                                                  Note that the development environment WeChat DevTools block this feature by default. In order to enable it, the user should open the Project Settings and check the box 'Does not verify valid domain names, web-view (business domain names), TLS versions and HTTPS certificates.'.

                                                                                                  [1] https://developers.weixin.qq.com/miniprogram/en/dev/framework/ability/network.html

                                                                                                  Source https://stackoverflow.com/questions/64023810

                                                                                                  QUESTION

                                                                                                  Where is the submit button in a WeChat Official Account app?
                                                                                                  Asked 2020-Mar-17 at 07:21

                                                                                                  I am trying to follow the WeChat Official Account tutorial to build an app.

                                                                                                  In the step of

                                                                                                  1.4 Basic Configuration for Developers

                                                                                                  1. After the restart is successful (python main.py 80), click the Submit button. If the prompt "token verification failed" appears, check the code or network link. If the token is successfully verified, you will be redirected back to the Basic Configuration page. Click Start.

                                                                                                  However, based on the tutorial, there is no submit button related code. I cannot find the submit button.

                                                                                                  When I open the pages through WeChat Official Account in the app WeChat, it just shows "hello, this is handle view".

                                                                                                  Any guide? Thanks

                                                                                                  main.py

                                                                                                  import web
                                                                                                  from handle import Handle
                                                                                                  
                                                                                                  urls = (
                                                                                                      '/wx', 'Handle',
                                                                                                  )
                                                                                                  
                                                                                                  if __name__ == '__main__':
                                                                                                      app = web.application(urls, globals())
                                                                                                      app.run()
                                                                                                  

                                                                                                  handle.py

                                                                                                  import hashlib
                                                                                                  import web
                                                                                                  
                                                                                                  class Handle(object):
                                                                                                      def GET(self):
                                                                                                          try:
                                                                                                              data = web.input()
                                                                                                              if len(data) == 0:
                                                                                                                  return "hello, this is handle view"
                                                                                                              signature = data.signature
                                                                                                              timestamp = data.timestamp
                                                                                                              nonce = data.nonce
                                                                                                              echostr = data.echostr
                                                                                                              token = "xxxx" #Enter the value in **Basic Configuration ** at Official Accounts Platform.
                                                                                                  
                                                                                                              list = [token, timestamp, nonce]
                                                                                                              list.sort()
                                                                                                              sha1 = hashlib.sha1()
                                                                                                              map(sha1.update, list)
                                                                                                              hashcode = sha1.hexdigest()
                                                                                                              print "handle/GET func: hashcode, signature: ", hashcode, signature
                                                                                                              if hashcode == signature:
                                                                                                                  return echostr
                                                                                                              else:
                                                                                                                  return ""
                                                                                                          except Exception, Argument:
                                                                                                              return Argument
                                                                                                  

                                                                                                  ANSWER

                                                                                                  Answered 2020-Mar-17 at 07:21

                                                                                                  I figured out the submit button here in the tutorial is referring the submit button at

                                                                                                  https://mp.weixin.qq.com/

                                                                                                  开发 -> 基本配置 -> 服务器配置 -> 修改配置 -> URL

                                                                                                  After you fill the URL, that submit (提交) button.

                                                                                                  (Unfortunately, the WeChat Official Accounts settings panel only has Mandarin language not like the developer doc. But hopefully my screenshot will help locate it.)

                                                                                                  Source https://stackoverflow.com/questions/60717017

                                                                                                  QUESTION

                                                                                                  Add random Font Awesome icons to html
                                                                                                  Asked 2020-Mar-07 at 00:44

                                                                                                  so, I am trying to add a random element to my site with Font Awesome icons that change on reload. I found a helpful post, here, but I can't find a way to make the code work. I am getting the console log, but no icon is displayed. I've tried assigning my an id and having the Jquery add a random class to that, but that doesn't seem to work. Any ideas?

                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                      
                                                                                                  

                                                                                                  ANSWER

                                                                                                  Answered 2020-Mar-06 at 21:49

                                                                                                  Your error description is not very precise, but I assume that the problem is that you are not adding the class (string), but its index.

                                                                                                  Try replacing

                                                                                                  $("#ranI").addClass("fas fa-", randIcon);
                                                                                                  

                                                                                                  with

                                                                                                  $("#ranI").addClass("fa fa-" + iconArray[randIcon]);
                                                                                                  

                                                                                                  Source https://stackoverflow.com/questions/60572050

                                                                                                  QUESTION

                                                                                                  how to use selenium to take full screenshot with lots of dynamic loading images?
                                                                                                  Asked 2020-Feb-02 at 22:33

                                                                                                  For example, I want to take a screenshot of this, but I'm only getting the following screenshot with the embedded code. What should I do?

                                                                                                  import time
                                                                                                  from selenium import webdriver
                                                                                                  from selenium.webdriver.chrome.options import Options
                                                                                                  
                                                                                                  def test_fullpage_screenshot():
                                                                                                      chrome_options = Options()
                                                                                                      chrome_options.add_argument('--headless')
                                                                                                      chrome_options.add_argument('--start-maximized')
                                                                                                      driver = webdriver.Chrome(chrome_options=chrome_options)
                                                                                                      driver.get("https://mp.weixin.qq.com/s/cg4qHhta8nLx93PDaW1dHQ")
                                                                                                      time.sleep(2)
                                                                                                  
                                                                                                      height = driver.execute_script("return document.body.scrollHeight")
                                                                                                      driver.set_window_size(1000, height)      #the trick
                                                                                                      driver.save_screenshot("screenshot1.png")
                                                                                                      driver.quit()
                                                                                                  

                                                                                                  ANSWER

                                                                                                  Answered 2020-Feb-02 at 21:44

                                                                                                  This website is using lazy loading for images. Usually, it works by checking which images are in the viewport. It does it once on page load, and then on scroll.

                                                                                                  So part of the solution would be to do this after you set the viewport :

                                                                                                  driver.execute_script("window.scrollTo(0, 100)")
                                                                                                  

                                                                                                  But it won't work as-is, since there is no space to scroll (your viewport includes the whole page).

                                                                                                  Hence, you could:

                                                                                                  • Set the viewport height to height - 100
                                                                                                  • Scroll down by 100px to trigger the lazy load
                                                                                                  • Scroll back to the top
                                                                                                  • Set the viewport height to height
                                                                                                  height = driver.execute_script("return document.body.scrollHeight")
                                                                                                  driver.set_window_size(1000, height - 100)
                                                                                                  driver.execute_script("window.scrollTo(0, 100)")
                                                                                                  driver.execute_script("window.scrollTo(0, 0)")
                                                                                                  driver.set_window_size(1000, height)
                                                                                                  time.sleep(2) # new images need time to load
                                                                                                  driver.save_screenshot("screenshot1.png")
                                                                                                  

                                                                                                  Source https://stackoverflow.com/questions/60030539

                                                                                                  QUESTION

                                                                                                  Wechat H5 payment does not work
                                                                                                  Asked 2019-Sep-27 at 02:58

                                                                                                  I have successfully integrated qr code wechat payment. It is pretty much pointless for mobile website. Client wants something more usable. After some research I have found that H5 payment should do. The thing is I am getting error and can't find anything on the web regarding the issue. The support is probably the worst I have ever dealt with. They tried to point to wrong config being used but when got full payloads, request and responses haven't come back with anything useful.

                                                                                                  endpoint: https://api.mch.weixin.qq.com/pay/unifiedorder

                                                                                                  payload:

                                                                                                  
                                                                                                    *appid*
                                                                                                    *merchantId*
                                                                                                    Tickets
                                                                                                    {"goods_detail":[[{"goods_id":"3_81","goods_name":"Wicked - 7 June 2018 07:30pm - STALLS K36","quantity":1,"price":1}]]}
                                                                                                    *11111*
                                                                                                    CNY
                                                                                                    1
                                                                                                    192.168.22.1
                                                                                                    20180602063844
                                                                                                    https://xyz2.local/wechat/confirmation/dfsdfs/erefdav
                                                                                                    MWEB
                                                                                                    *nonce*
                                                                                                    *sign*
                                                                                                  
                                                                                                  

                                                                                                  response:

                                                                                                  
                                                                                                     FAIL
                                                                                                     商户号该产品权限预开通中,请等待产品开通后重试
                                                                                                  
                                                                                                  

                                                                                                  For wechat integration I am using this library: omnipay-wechat All the data between ** is correctly populated. Google translation doesn't make much sense to me. Tried to google for the error in Chinese but haven't found anything helpful.

                                                                                                  Wasted already a lot of time.. Hope there is somebody witch wechat payment expierience that can point me to the right direction.

                                                                                                  ANSWER

                                                                                                  Answered 2018-Aug-15 at 06:53

                                                                                                  The error means the account linked to the given merchant id does not have the privileges yet for the request, you have to wait until the account get the approval and then try again.

                                                                                                  Source https://stackoverflow.com/questions/51812919

                                                                                                  QUESTION

                                                                                                  WeChat Social Login
                                                                                                  Asked 2019-Jun-19 at 13:43

                                                                                                  I'm trying to integrate WeChat login with current system.

                                                                                                  I own a WeChat offical account and already have AppID and AppSecret.
                                                                                                  Server Settings enabled as well.

                                                                                                  When I was tring to hit the QRcode scan url with my appid and my own server redirect url as parameter(example as below)

                                                                                                  https://open.weixin.qq.com/connect/qrconnect?appid=wxbdc5610cc59c1631&redirect_uri=https%3A%2F%2Fpassport.yhd.com%2Fwechat%2Fcallback.do&response_type=code&scope=snsapi_login&state=3d6be0a4035d839573b04816624a415e#wechat_redirect
                                                                                                  

                                                                                                  The browser threw me this error page

                                                                                                  What I expect is something like this

                                                                                                  Question:

                                                                                                  1. Is it because of I didn't go through the wechat verification thus unable to obtain the user basic information?

                                                                                                  2. How to get the wechat verification?

                                                                                                  ANSWER

                                                                                                  Answered 2017-Jun-23 at 02:53
                                                                                                  1. Is it because of I didn't go through the wechat verification thus unable to obtain the user basic information?

                                                                                                    Yes. To integrate wechat login, your wechat official account must be verified service account (subscribe account is not supported, even it is verified). Please refer to official document for more information.

                                                                                                  2. How to get the wechat verification?

                                                                                                    To get the wechat official account verified, you can follow the steps in the customer support document.

                                                                                                  Source https://stackoverflow.com/questions/44667660

                                                                                                  QUESTION

                                                                                                  NativeScript navigate to another page from custom Android activity
                                                                                                  Asked 2019-May-12 at 19:21

                                                                                                  I am developing an APP with wechat login feature. After getting approval from wechat it will call a custom activity of my NativeScript APP. I am getting response correctly but how can I move to another page instated of the home page after doing some verification. I am using NativeScript + Angular.

                                                                                                  Sample code

                                                                                                  getJSON("https://api.weixin.qq.com/sns/oauth2/access_token?appid=ID&secret=SECRET&code=" + res.code + "&grant_type=authorization_code").then((res) => {
                                                                                                      console.dir(res);
                                                                                                      // ===> here I want navigation
                                                                                                  }, err => {
                                                                                                      console.dir(err);
                                                                                                  })
                                                                                                  

                                                                                                  I tried like this:

                                                                                                  frame.topmost().navigate("src/app/login/login.component");
                                                                                                  

                                                                                                  but getting error:

                                                                                                  JS: Unhandled Promise rejection: Cannot set property '_moduleName' of undefined ; Zone: ; Task: Promise.then ; Value: TypeError: Cannot set property '_moduleName' of undefined TypeError: Cannot set property '_moduleName' of undefined

                                                                                                  Please give me some suggestions. Thanks in advance :)

                                                                                                  ANSWER

                                                                                                  Answered 2019-May-12 at 19:04

                                                                                                  A similar problem cost me an entire Weekend, without knowing how the companion controller .js or .ts files look like I can only recommend you go to the basics / source:

                                                                                                  https://docs.nativescript.org/core-concepts/navigation#frame

                                                                                                  it helped me find the problem in my code.

                                                                                                  If you wrote a custom Page that does not start from a template chances are you wrote the controller too and it's easy to overlook some line that is present in the samples - even thou it looks like you don't need it.

                                                                                                  If you paste your controller JS we could understand your context.

                                                                                                  For instance, here is piece of code you should definitely include to help you debug:

                                                                                                  in your page-you-navigate-to.xml

                                                                                                  
                                                                                                  ...
                                                                                                  
                                                                                                  

                                                                                                  in your page-you-navigate-to.ts

                                                                                                  import { EventData } from "tns-core-modules/data/observable";
                                                                                                  import { Page } from "tns-core-modules/ui/page";
                                                                                                  
                                                                                                  export function onPageLoaded(args: EventData): void {
                                                                                                      const page = args.object;
                                                                                                      var context = page.navigationContext;
                                                                                                      page.bindingContext = context;
                                                                                                      console.log("Target page Loaded.");
                                                                                                  }
                                                                                                  

                                                                                                  Start your debugger, and step through see where you have null values and read up on those method calls and their parameters.

                                                                                                  Source https://stackoverflow.com/questions/56098285

                                                                                                  QUESTION

                                                                                                  Wechat - unable to send rich media messages more than 1
                                                                                                  Asked 2019-Feb-27 at 23:38

                                                                                                  I hit the below request to display 2 articles but the api is giving error code - 45008. Although, it is working with 1 article

                                                                                                  https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='My_Token' Method: POST Body:

                                                                                                  {
                                                                                                      "touser": "OPENID",
                                                                                                      "msgtype": "news",
                                                                                                      "news": {
                                                                                                          "articles": [
                                                                                                              {
                                                                                                                  "title": "Happy Day",
                                                                                                                  "description": "Is Really A Happy Day"
                                                                                                              },
                                                                                                              {
                                                                                                                 "title": "Happy",
                                                                                                                  "description": "Is goof"
                                                                                                              }
                                                                                                          ]
                                                                                                      }
                                                                                                  }
                                                                                                  

                                                                                                  Error:

                                                                                                  {
                                                                                                      "errcode": 45008,
                                                                                                      "errmsg": "article size out of limit hint: [1kiZGA01844123]"
                                                                                                  }
                                                                                                  

                                                                                                  ANSWER

                                                                                                  Answered 2019-Feb-27 at 23:38

                                                                                                  According to the Chinese docs it would seem that you can no longer send more than 1 article.

                                                                                                  图文消息条数限制在1条以内,注意,如果图文数超过1,则将会返回错误码45008 (Google Translate: The number of text messages is limited to one. Note that if the number of pictures exceeds 1, the error code 45008 will be returned.)

                                                                                                  https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547

                                                                                                  Unfortunately it looks like the English documentation has not yet been updated to reflect this change.

                                                                                                  Curious to know if anybody has found a workaround / new message type that could be used similarly instead?

                                                                                                  Source https://stackoverflow.com/questions/53650212

                                                                                                  QUESTION

                                                                                                  c# URL POST Web API
                                                                                                  Asked 2018-Oct-31 at 20:45

                                                                                                  I'm trying to do a function which work with WECHAT API, Here is my code:

                                                                                                  I use the code below to get a connection Token

                                                                                                  internal static string Token(string CorpID, string Secret)
                                                                                                      {
                                                                                                          CorpID = CorpID ?? "wwe1f80304633";
                                                                                                          Secret = Secret ?? "Ev7_oVN7RqD9k4yUy5pzkfcZ_QhX9l0VjZnAQ";
                                                                                                  
                                                                                                          string token;
                                                                                                          using (var wc = new WebClient())
                                                                                                          {
                                                                                                              token = wc.DownloadString($"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CorpID}&corpsecret={Secret}");
                                                                                                          }
                                                                                                          if (token.Contains("access_token"))
                                                                                                          {
                                                                                                              return token.Split(',')[2].Split(':')[1].Replace("\"", "");
                                                                                                          }
                                                                                                          return "";
                                                                                                      }
                                                                                                  

                                                                                                  It's successful to get a valid token from WECHAT Server,

                                                                                                  And the code below is I want to POST a request to WECHAT API and ask WECHAT to Send Message to selected Department Person.

                                                                                                  internal static string SendMsg(string sendtext)
                                                                                                      {
                                                                                                  
                                                                                                          string ACTOKEN = "" + PDC.MSGTOKEN + "";
                                                                                                          string CONTENT = "" + PDC.CONTENT + "";
                                                                                                          string PostUrl;
                                                                                                          using (var wc2 = new WebClient())
                                                                                                          {
                                                                                                              PostUrl = wc2.UploadString($"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}{1}", ACTOKEN, CONTENT);
                                                                                                          }
                                                                                                  
                                                                                                  
                                                                                                          return "";
                                                                                                      }
                                                                                                  
                                                                                                  public static void SendMsg2()
                                                                                                      {
                                                                                                  
                                                                                                          PDC.CONTENT = "Test Message";
                                                                                                          string MsgContent = "{\"toparty\": \"" + PDC.DEPTID + "\",\"msgtype\": \"text\",\"agentid\": \"" + PDC.AGENTID + "\",\"text\": {\"content\": \"" + PDC.CONTENT + "\"},\"safe\":0}";
                                                                                                          SendMsg(MsgContent);
                                                                                                  
                                                                                                          MessageBox.Show("" + MsgContent + "");
                                                                                                      }
                                                                                                  

                                                                                                  And I Added a button on my WinForm and trying to make it work

                                                                                                  private void BtnSendMsg_Click(object sender, EventArgs e)
                                                                                                      {
                                                                                                          string token = MSG.Token(null, null);
                                                                                                          if (!string.IsNullOrEmpty(token))
                                                                                                          {
                                                                                                              PDC.MSGTOKEN = token;
                                                                                                              MessageBox.Show("" + PDC.MSGTOKEN + "");
                                                                                                          }
                                                                                                          else
                                                                                                          {
                                                                                                              MessageBox.Show(" Invalid Token ");
                                                                                                          }
                                                                                                  
                                                                                                          MSG.SendMsg2();
                                                                                                      }
                                                                                                  

                                                                                                  However seems it doesn't work, and if I'm not wrong the problem on this part

                                                                                                  internal static string SendMsg(string sendtext)
                                                                                                      {
                                                                                                  
                                                                                                          string ACTOKEN = "" + PDC.MSGTOKEN + "";
                                                                                                          string CONTENT = "" + PDC.CONTENT + "";
                                                                                                          string PostUrl;
                                                                                                          using (var wc2 = new WebClient())
                                                                                                          {
                                                                                                              PostUrl = wc2.UploadString($"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}{1}", ACTOKEN, CONTENT);
                                                                                                          }
                                                                                                  
                                                                                                  
                                                                                                          return "";
                                                                                                      }
                                                                                                  

                                                                                                  May anyone can give me some ideas how I can solve this problem ? Many Many Many Thanks ~

                                                                                                  ANSWER

                                                                                                  Answered 2018-Oct-31 at 20:45

                                                                                                  I has been done my Code without Problem, this is the code below for everyone who need.

                                                                                                  The code to get Token from Https API

                                                                                                  internal static string Token(string CorpID, string Secret)
                                                                                                      {
                                                                                                          CorpID = CorpID ?? "" + PDC.CorpID + "";
                                                                                                          Secret = Secret ?? "" + PDC.Secret + "";
                                                                                                  
                                                                                                          string token;
                                                                                                          using (var wc = new WebClient())
                                                                                                          {
                                                                                                              token = wc.DownloadString($"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CorpID}&corpsecret={Secret}");
                                                                                                          }
                                                                                                          if (token.Contains("access_token"))
                                                                                                          {
                                                                                                              return token.Split(',')[2].Split(':')[1].Replace("\"", "");
                                                                                                          }
                                                                                                          return "";
                                                                                                      }
                                                                                                  

                                                                                                  The Method of POST

                                                                                                  internal static string PostWebRequest(string PostUrl, string ParamData, Encoding DataEncode)
                                                                                                      {
                                                                                                          string ret = string.Empty;
                                                                                                          try
                                                                                                          {
                                                                                                              byte[] byteArray = DataEncode.GetBytes(ParamData);
                                                                                                              HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(PostUrl));
                                                                                                              webReq.Method = "POST";
                                                                                                              webReq.ContentType = "application/x-www-form-urlencoded";
                                                                                                  
                                                                                                              webReq.ContentLength = byteArray.Length;
                                                                                                              Stream newStream = webReq.GetRequestStream();
                                                                                                              newStream.Write(byteArray, 0, byteArray.Length);
                                                                                                              newStream.Close();
                                                                                                              HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                                                                                                              StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
                                                                                                              ret = sr.ReadToEnd();
                                                                                                              sr.Close();
                                                                                                              response.Close();
                                                                                                              newStream.Close();
                                                                                                          }
                                                                                                          catch (Exception ex)
                                                                                                          {
                                                                                                              return ex.Message;
                                                                                                          }
                                                                                                          return ret;
                                                                                                      }
                                                                                                  

                                                                                                  The code to using WECHAT WORK for sending Message

                                                                                                  internal static string SendMsg(string CorpID, string Secret, string ParamData, Encoding DataEncode)
                                                                                                      {
                                                                                                          string AccessToken = Token(CorpID, Secret);
                                                                                                          string PostUrl = string.Format("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}", AccessToken);
                                                                                                  
                                                                                                          return PostWebRequest(PostUrl, ParamData, DataEncode);
                                                                                                      }
                                                                                                  
                                                                                                  public static void SendMsg2()
                                                                                                      {
                                                                                                          string sCorpID = "" + PDC.CorpID + "";
                                                                                                          string sSecret = "" + PDC.Secret + "";
                                                                                                          PDC.CONTENT = "Test Message";
                                                                                                  
                                                                                                          string Message = "Test";
                                                                                                  
                                                                                                  
                                                                                                          string MsgContent = "{";
                                                                                                          MsgContent += "\"totag\": \"" + PDC.DEPTID + "\",";
                                                                                                          MsgContent += "\"msgtype\": \"text\",";
                                                                                                          MsgContent += "\"agentid\": \"" + PDC.AGENTID + "\",";
                                                                                                          MsgContent += "\"text\": {";
                                                                                                          MsgContent += "  \"content\": \"" + Message + "\"";
                                                                                                          MsgContent += "},";
                                                                                                          MsgContent += "\"safe\":\"0\"";
                                                                                                          MsgContent += "}";
                                                                                                  
                                                                                                          SendMsg(sCorpID, sSecret, MsgContent, Encoding.UTF8);
                                                                                                      }
                                                                                                  

                                                                                                  The Button Event for active Send Message Function

                                                                                                  private void BtnSendMsg_Click(object sender, EventArgs e)
                                                                                                      {
                                                                                                          string token = MSG.Token(null, null);
                                                                                                          if (!string.IsNullOrEmpty(token))
                                                                                                          {
                                                                                                              PDC.MSGTOKEN = token;
                                                                                                          }
                                                                                                  
                                                                                                          MSG.SendMsg2();
                                                                                                      }
                                                                                                  

                                                                                                  Source https://stackoverflow.com/questions/53089187

                                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                                  Vulnerabilities

                                                                                                  No vulnerabilities reported

                                                                                                  Install weixin

                                                                                                  You can download it from GitHub.

                                                                                                  Support

                                                                                                  For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                                  Find more information at:
                                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                  Find more libraries
                                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                  Save this library and start creating your kit
                                                                                                  CLONE
                                                                                                • HTTPS

                                                                                                  https://github.com/game-helper/weixin.git

                                                                                                • CLI

                                                                                                  gh repo clone game-helper/weixin

                                                                                                • sshUrl

                                                                                                  git@github.com:game-helper/weixin.git

                                                                                                • Share this Page

                                                                                                  share link

                                                                                                  Reuse Pre-built Kits with weixin

                                                                                                  Consider Popular Runtime Evironment Libraries

                                                                                                  Try Top Libraries by game-helper

                                                                                                  search

                                                                                                  by game-helperJavaScript

                                                                                                  Compare Runtime Evironment Libraries with Highest Support

                                                                                                  node

                                                                                                  by nodejs

                                                                                                  electron

                                                                                                  by electron

                                                                                                  Rocket.Chat

                                                                                                  by RocketChat

                                                                                                  TypeScript

                                                                                                  by microsoft

                                                                                                  express

                                                                                                  by expressjs

                                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                  Find more libraries
                                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                  Save this library and start creating your kit